Different Outcome to Mosh in "20- Exercise- Prime Numbers" Lesson

Hi there, in the " Ultimate JavaScript Part 1: Fundamentals" course, for the “20- Exercise- Prime Numbers” lesson, I get all numbers, not just prime, even though my code matches Mosh exactly? I’m not sure if something’s been updated in JavaScript that now breaks that code or if I’m just missing something obvious?

you have to increment the factor.


function showPrime(limit){
for (let number = 2;number <= limit; number++){
let isPrime  = true;
for (let factor = 2; factor < number; factor++){
if(number % factor  === 0){
isPrime = false;
if(isPrme) console.log(number)

copy past this code and run it…

good luck

Thanks - but that’s essentially what I’ve written and it doesn’t work. My code is identical to Mosh’s code but it’s not working.

not the same

This is not the same as in the video, if your screenshot hasn’t done some pixel magic. You’re not setting your isPrime to false, you’re setting letPrime to false, which doesn’t exist.

1 Like

Goodness me, I combed through that code 3 times over and missed that! Thanks so much, working now :slight_smile:

1 Like