Why is my code not going through?


#1


https://www.codecademy.com/courses/javascript-beginner-en-ASGIv/0/2?curriculum_id=506324b3a7dffd00020bf661


Once I press the Save and submit button, it won't do anything else. It says it already has finished loading. I tried this on two different computers and it happened on both. Do you think both of them are messed up or is there something wrong with my code? Please help!


var understand = true;

while( 5 <= 10 ){
	console.log("I'm learning while loops!");
	understand = false;
}


#2

You created an infinite loop with your while condition. You assigned true to understand in the 1st line. That is unaffected by your condition. Changing understand to false in your loop doesn't affect (5<=10). It only assigns a new value to understand.

You need to input a condition that will be affected by changing understand to false.


#3

Thank you so much!

So what would you put instead if you were to get the code working?


#4

What was the reason you assigned true to understand?


#5

It was set like that already. I tried fixing it, but it froze up again. I tried changing the while loop and it ran through but said to check my syntax.


#6

Can you post the code you have?

Think about this for your loop. If you are changing the value of understand after your console.log statement runs to make the loop stop, what could you use as the condition to make the loop initially run?


#7

I changed it to this...

var understand = true;

while( 5 == 10 ){
console.log("I'm learning while loops!");
understand = false;
}

It says, "Oops, try again. It looks like you didn't print the string to the console. Check your loop syntax!"


#8

Put the variable in the loop condition, run the loop, see what happens.


#9

Thank you so much!!! I fixed it and it ran through.
Even if it did go through, can you see if this looks right please?

var understand = true;

while( understand ){
console.log ("I'm learning while loops!");
var understand = false;
}

Thank you again.


#10

What's more important than the code looking right is understanding the while loop :slight_smile:


#11

Thank you so much! All of this helped me understand while loops. It has been coming to me much easier now. :smile: :clap:


#12

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