I am Lost with "while Loops"


#1

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

I have no idea what I'm supposed to do, it keeps telling me "Oops, try again. It looks like you didn't print the string to the console. Check your loop syntax!"

var understand = true;

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

#2

Check your while condition. If you assign a variable a value, the following code generally uses the variable. Otherwise, why declare a variable? I see you have included the variable in your loop and changed the value to false to stop the loop. To get the while loop to execute, where can you place your variable in order to possibly trigger your loop?


#3

The condition is not correct. Change the condition to (understanding) or to (understanding ==1) and it'l work. From the look of your condition as it is, you're saying while false which is 0 is assigned the value true, which is 1,


#4

Why does the console.log("I'm learning while loops!"); need to be repeated? It appears on line 4.
LO26


#5

var understand = true;

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

This is the correct code, as we are instilling the var understand = true, in while loop we have to put only the variable i.e. understand and the condition goes true.


#6

Thank you.
A practical answer finally.


#7

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