1
        var num=8;
var isPrimeT=true;
var iw=2;
while(iw<isPrimeT){
  if(num%iw==0){
    isPrimeT=false;
    break;
  }
  iw++;
}
if(isPrimeT==false){
  console.log(num+" is not a prime number");
}
else{
  console.log(num+" is a prime number");
}

Is there anything wrong? it does not show the correct answer. When I input the variable "num", it only shows num+"is a prime number".

Muhammad
  • 13
  • 3
  • 1
    Learn about [how to debug small programs](//ericlippert.com/2014/03/05/how-to-debug-small-programs). [Rubber Duck Debug](//rubberduckdebugging.com/) your code. Please try using the [debugging capabilities](//ali-dev.medium.com/how-to-easily-debug-in-javascript-5bac70f94f1a) of your browser. What do you think does `iw < isPrimeT` mean? – Sebastian Simon Feb 16 '22 at 06:52
  • 2
    yes, it will never enter your while loop as the condition for comparison in while loop will always be false – Master.Deep Feb 16 '22 at 06:52
  • Does this answer your question? [Number prime test in JavaScript](https://stackoverflow.com/questions/40200089/number-prime-test-in-javascript) – Maik Hasler Feb 16 '22 at 06:54

0 Answers0