2. While Syntax

My webpage seemed to freeze multiple times when I clicked submit code. I tried this on firefox too, and it had the same problem.

var understand = true;

console.log(“I’m learning while loops!”);
understand = false;

I didn’t change line 5 like it said not to. When I clicked submit code, it showed the button being pressed and the cursor just turned into a hand and froze

Your webpage keeps freezing because you threw an Infinite loop into your solution. 5 will always be less than 8 NO MATTER WHAT. so if the statement is always true. It will continuously create it. Loops will continue to go on until theirjob is completed.

but didnt it later state understand is false to stop the loop?

You must set the condition to “understand”. Otherwise you will simply be putting in a true condition that stays true. If your condition is, for instance, 5<8, that is true, and setting the variable “understand” to be false does not alter the validity of the condition of 5<8.

You beat me to it… Why D;

continued – since setting “understand” to false does not change the argument to false, the while loop will continue infinitely, thus overloading your browser, which is why it’s freezing.

Sorry, my bad. I’ll delete my reply if you’d like to take over.

No it’s okay. As long as they understand it and get end results you’re fine.

Should they have any more questions I will leave them up to you.

No no no you got it :smiley: I promise

Thanks all for the help.

While loop: here is my code"
var count =0;

var loop = function(phrase){
while (count++ < 3){

loop(“I’m looping”);

I get the 3 “I’m looping” phrases printed out, BUT, I get this message – “Oops, try again. It looks like you’re not printing the right string to the console.” – and can’t move on. What is the error?


Get rid of phrase in var loop = function(), get rid of the ++ in count++ < 3. make the console.log phrase to actually say the phrase I’m looping! and instead of having count++ in right after the while change to count++ to be after the console.log

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.