Please help my find this syntax error!


#1


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


Apparently there is a syntax error, but I cant find it. This is the error message that I got:

"Oops, try again. There was a problem with your syntax."
I also put it through an online syntax checker and this is the error message that it gave me:

"Error: Line 16: Unexpected token ("

Please help me fix this error. I have tried many different things but still no success.


// Write your code below!

for (i = 1; i <= 5; i++;) {
console.log("The variable is less than or equal to 5");
}

var i2 = 1
while (i2 <= 5) {
    console.log("The variable is less than or equal to 5");
}

var i3 = 1

do {
    console.log("The variable is less than or equal to 5");
} (i3 <= 5);


#2
for (i = 1; i <= 5; i++;) {
console.log("The variable is less than or equal to 5");
}

there is an ";" after i++ in the declaration of the for loop that lead to your syntax error.

arnome.


#3

in addition to what @arnome said, the while and do/while loops are infinite loops as the condition is true and is never changed so it stays true forever.
For an overview on loops maybe have a look at this:


#4

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