So I'm coding something in p5.js to check whether a number is prime or not. Here's the function:
function prime(n) {
let P = true;
for (let i = 2; i <= sqrt(n); i++) {
if (n%i == 0) {
P = false; break;
} else {
P = true; break;
}
} return P;
}
Everything works fine, except for the i <= sqrt(n) and if(n%i == 0) bits...
The % operator gives you the remainder of a/b, but when i type in:
prime(integer that ends with 5)
into the console, it returns true, when it should return false.
So I want to add a codtition that if the last digit of n is 5, return false. how do I do that?
Thanks!