2. While syntax


#1

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

I tried the code shown below, but received the error, "doesn't print the string to the console. I know it should be while(understand === true) instead, but why "true" instead of "1" if JavaScript assumes they mean the same thing?


var understand = true;

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


#2

1 and true are both considered true, however, you use 3 equal signs, this means the data type should also be a match for this condition to be true. One is a integer, the other a boolean value. So, the condition is false

so either change the number of equal signs to two, or use true boolean value in the condition


#3

var understand = true;

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

// you forgot to print out "I'm learning while loops!"


#4

...Tripped me up. I chose my own words inside the console.log parentheses.


#5

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