I am making a program that takes user input and then returns either true of false based on whether the number entered is prime. Prime = True, Not Prime = False. I am having trouble with the red colored code that follows. More specifically. The math is correct i think but I’m missing something.
<script type=”text/javascript”>
function frontWork() {
var n = parseFloat(document.getElementById(“inBox”).value);
var output = isPrime(n);
document.getElementById(“outBox”).value=output;
}
function isPrime(n) {
if (n == 1 || n == 2){
return true;
}
[COLOR=”Red”] for (var i=2;i<n;i++) {
if (num % i == 0) {
return true;
break;
}
if (n % i != 0) {
return false;
}
else {
return true;
}
}[/COLOR]
}
</script>