11. Review : Syntax Error


#1


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


I usually don't prefer coming to the forum for help; rather solving it on my own, but i've been stuck on this one for awhile. The error is: SyntaxError: Unexpected token } I'm guessing it's a silly mistake, but it's better to ask. Thank you!


var cooking = ["flour ", "eggs ", "and", "sugar"];
for(var i = 0; i < cooking.length; i++) {
    console.log("Now add the " + cooking[i]);
}

 var eggs = false;
 while(eggs) {
     console.log("Keep going!");
    eggs = true;
}
 
 
    var i = true;
  do {
    console.log("Hey.");
    
    } while(i);

}


#2

yes, it is a silly mistake

remove the "}" or add one, i leave it to you

open and close it :slight_smile:


#3

The last closing } is stray as there's no opening bracket thus the syntax error

BUT that isn't the only error in your code, if you run it your browser is going to crash as you have an infinite loop.

You haven't set any limit to the loops thus its going to keep on running till the browser freezes or crashes.


#4

whoops that would create an infinity loop


#5

ah thank you! I'll look through my old lessons :slight_smile:


#6

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