1 - loop continues to run or not


#1

"As long as the condition evaluates to true, the loop will continue to run. As soon as it's false, it'll stop. (When you use a number in a condition, as we did earlier, JavaScript understands 1 to mean true and 0 to mean false.)"

var coinFace = Math.floor(Math.random() * 2);

while(coinFace === 0){
	console.log("Heads! Flipping again...");
	var coinFace = Math.floor(Math.random() * 2);
}
console.log("Tails! Done flipping.");

0 is false, and in the exercise we had coinFace === 0, and loop runs until it reach 1, then stop and show ("Tails! Done flipping."). And you said that when condition is true (1, not false) the loop continues to run...


#2

Your question from all this is? or you are just making a note?


#3

its a question becouse i dont understand this. You said that loop runs when its true, and here loop runs when its false. So what is the difference?


#4

No run the code several times and see the result. you will realize that the results are never the same. It is sometimes juggling between just

Tails! Done flipping.
'
or
Heads! Flipping again...(any number of times) and then Tails! Done flipping.

The value of coinFace is changing between 0 and 1 so when it is 0 the loop will execute but when it is 1 then the loop will exit