Why is my condition wrong?


#1

Try it yourself—complete the while loop in the editor so it will print out "I'm learning while loops!". Do this by adding the condition between the parentheses—don't change line 5, or you could get an infinite loop!`

var understand = true;

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

Oops, try again. There was a problem with your syntax.

What did I do wrong?


#2
var understand = true;

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

This is my code that I used to print out the string "I'm learning while loops!" In a true/false statement, I do not think that you're supposed to put numbers in the while loop. If you put your variable to a number, like 0, then you can use it, also shown in JavaScript "Introduction to 'While' Loops in JS" 6/11.

Hope it helped!


#3

So what whould be the best condition example to put inside the parenthesies.


#4

I would put the variable inside the "While" loop.


#5

When I put in understand = true for the conditon my browser crashes,

var understand = true;

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


#6

This is what I mean. Sorry if I was being vague.

var understand = true;

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


#7

with understand = true, you set understand to be true and if you use console.log(understand = true) you can see that this has a value of true. Meaning you basically say while(true){} which is an infinite loop.


#8

Thank you so much! :grinning:


#9

I'm not the best explainer. :grin: