Hi guys,
I can understand what mosh did in the video. I am trying to do it another way but it always has problem. Can anyone tell me where the problem of my code is. thanks
showPrimes(10);
function showPrimes(num) {
for (let number = 2; number <= num; number++) {
let result;
for (let factor = 2; factor < number; factor++) {
if (number % factor === 0) {
result = 'NO'
} else {
result = number;
}
}
console.log(result);
}
}
the result from the console.log() is always 2,3,4,5,6,7,8,9