While Loop Review Error


#1

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

Idk what is wrong with my syntax but its not correct for some reason. The error reads: SyntaxError: Unexpected token =

Dont know what is wrong here


for(var i = 0; i < 4; i++){
    console.log(i);
};

var four = 4;
var five = 5;
while( four != five) {
    console.log("Math is my strong suite!");
    four ==== five;
};


var myCondition = false; 
var myName = 'Jelani';
do {
    console.log(myName);
} while(myCondition);


#2

==== is not a valid comparison operator. Try using ===.


#3

i didnt even see I had an extra "="! Thank you!


#4

That correction won't fix the loop. Something outside the loop has to stop it from running. A variable needs to be altered to make the loop condition false. Otherwise, you'll have an infinite while loop.


#5

I changed it to:

for(var i = 0; i < 4; i++){
console.log(i);
};

var understand = true
while(understand) {
console.log("Math is my strong suite!");
understand = false;
};

var myCondition = false;
var myName = 'Jelani';
do {
console.log(myName);
} while(myCondition);

and that worked, but my question is why? Like why did my changes work now rather than before


#6

Only because in the old code 4 === 5 is false


#7

If you had written four = 5 instead of four === five, then the while condition would be evaluate to (5 != five).


#8

Gotcha! Thank you, I understand now


#9

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