Apologies if this has been covered somewhere. I've searched through a lot of prime number function answers on here but I cannot seem to find the answer to my issue. I have cobbled together a function to check if a number is prime, and then I'm running a for loop for numbers under 100 and printing out primes. My code does not print primes. It seems to start printing primes, but then throws a 9 in there, and it gets worse from there.
I found code that is seemingly identical to mine that successfully prints primes to the console. Below is my code; where is my error? For the record I am using jsfiddle, and I am very new at this.
function isPrime(number) {
if (number < 2) {
return false;
}
for (var i = 2; i < number; i++) {
if (number % i == 0) {
return false;
} else {
return true;
}
}
};
for (var i = 0; i < 100; i++) {
if(isPrime(i)) {
console.log(i);
}
}