Assessment wanted for Loops 3 skill test C

I’m confused and having trouble completing it.
Here are the links: Codepen , Mdn.
Thank you for your help !

Hi @TheRealSuperhuman,

The first thing I did was to look at the console i.e. press F12 to see if there was any error being generated. You will still see it in codepen. In this case it stated

Uncaught We found an infinite loop in your Pen. We’ve stopped the Pen from running. Please correct it or contact support@codepen.io.

So I looked at the while statement which appears to be missing a colon at the end. Adding the colon didnt help :frowning:

Next this I noticed was that your itterator had “i–”, I think this is normally put in as --i. Sadly it didnt help either. :pensive:

Next thing I did was change your do statement. The initial if statement can be simplified to “if(isPrime(i))” which will generate true or false. As we only want to add to the paragraph if the statement is true we dont need the else statement. So the code looked like this

Do {
if(isPrime(i)) {
do action;
}
–i;
} while(i >1);

This worked :smile:
The question is why didnt your orginal do not work? I suspect that the do while cannot have an else statement but dont quote me on this.
Fun isnt it :joy:

Thank you, but I still don’t understand how does the isPrime argument changes anything to the result of the function being run. It always return :
499, 491, 487, 479, 467, 463, 461, 457, 449, 443, 439, 433, 431, 421, 419, 409, 401, 397, 389, 383, 379, 373, 367, 359, 353, 349, 347, 337, 331, 317, 313, 311, 307, 293, 283, 281, 277, 271, 269, 263, 257, 251, 241, 239, 233, 229, 227, 223, 211, 199, 197, 193, 191, 181, 179, 173, 167, 163, 157, 151, 149, 139, 137, 131, 127, 113, 109, 107, 103, 101, 97, 89, 83, 79, 73, 71, 67, 61, 59, 53, 47, 43, 41, 37, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2,.

I dont really understand what you mean. What were you expecting? Can you describe it to me? maybe even run through how you think the code runs?

I’ve found the answer, I tried to add a line to run the function like : isPrime(22); or isPrime(17665); and it always give me the same result.

I now understand that the variable I is the argument for the function.

1 Like

Nice work! :sunglasses:

“Figuring things out for yourself is the only freedom anyone really has. Use that freedom” (Jean Rasczak, Starship Troopers)