3. A fellow of Infinite Loops - strings don't work?


#1

Basically, I intend to "understand" from a boolean into a string to make it "untrue".

But this doesn't work? Why not?

understand = true;

while(understand){
	console.log("I'm learning while loops!");
	//Change the value of 'understand' here!
	understand = "stringed";
	console.log(understand);
}


#2

because strings are considered true? you could use a string to make it false, but then you would have to compare understand with true:

while(understand === true)

#3

understand = true;

while(understand){
console.log("I'm learning while loops!");
//Change the value of 'understand' here!
understand = false;
console.log("This is false")
}

You claim 'understand' as true in the first line to define it's value. To prevent the block of code from being an infinite loop you have to again claim 'understand' as False, followed by a 'console.log' with a message.


#4

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