I'm trying to stretch my Javascript knowledge so I'm setting little targets for myself. I wanted to log the prime numbers between 1-100, and I created this code. How can this be improved in vanilla Javascript?
for (var i=2; i<=100; i++) {
// specifically identify 2,3,5,7
else if (counter === 2 || counter === 3 || counter === 5 || counter === 7 ) {
console.log(counter);
}
// anything that doesn't divide by 2,3,5,7 is prime
else if (counter % 2 !== 0 && counter % 3 !== 0 && counter % 5 !== 0 && counter % 7 !== 0) {
console.log(counter);
}
}
I'm aware this might be closed, but I wanted to make sure there's not a glaring error or easier solution staring me in the face. Thanks!