What is the problem?


#1

Can somebody explain what's wrong with my code then? I've followed along but still am stuck. I'm coming back to codecademy after a 2 month hiatus and left off in a tricky spot.

var understand = true;

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


2. while syntax
#2

Please do no hijack other peoples posts, I made this question a separate post pls do this yourself next time. (if you want to change the title do it)

What is your problem and what error message do you get? From what I see your loop is not run because understand is true and you compare it to 1, although 1 and true have the same value their type is not the same so this condition is false and the loop is skipped. The {} around the text:

 {
	understand === 0;
	console.log("oh no!");
}

are not necessary neither is the understand === 0 which again computes to false but is never used anywhere.


#3

Sorry about that, first time using the forums.

Basically I made it partially through the intro to while loops and took a few months off for work. Now I'm back at it, and completely lost. I thought I had it evaluate to true, but it would run the false string instead of the true one. (oh no!).


#4

Well it is no either or like the if/else but a "first this then that". So you first do the while loop the condition is false so you go on with this:

 {
	understand === 0;
	console.log("oh no!");
}

So to make this run you probably need to make the condition become true e.g. understand === true or just understand and then inside the while loop you need to change the value of understand so that it is no longer true to avoid being stuck in an infinite loop. And it is really important that this is done inside of the loop e.g. by understand = false because if it is placed after the loop you will only reach it when the loop is done which will never happen because you cannot reach this statement. Hope this is not too confusing.


#5

thank you very much!!


#6

You made a {} where there should be one, js cant really see what you are trying to do, use an if/else statement.

Your while loop ends here:
while(understand === 1){
console.log("I'm learning while loops!");
}

Then you start an unknown statement/loop or whatever your intension was:
{
understand === 0;
console.log("oh no!");
}

I'd recommend this:
while(understand){
console.log("I'm learning while loops!");
}

if(understand === 0){
console.log("oh no!");
}