Hello good people, as a novice programmer, I was assigned to write code in JS to detect a prime number or not. This is what I’ve done with all my little knowledge. This is very simple and devoid of complex code.
var num = 99;
if(num<2){
console.log("invalid input");
}
if(num>1){
for( var i=2; i<num; i++) {
if(num % i==0){
console.log(num + " is not prime");
break;
}else{
console.log(num + " is prime")
break;
}
}
}
and the answer is
99 is prime
That’s not true. I know, many of you can write highly efficient code with advanced syntax. I do not expect such a sophisticated solution. What is actually missing in my code that can make my program functional?