Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge

Michael L
Michael L
2,482 Points

What is causing this "Unexpected token { error" ?

Hello, I debugged a few parts of my code, but this error seems to persist. (Trying to debug using Chrome Developer Tools / Console.)

This is the error I receive: Uncaught SyntaxError: Unexpected token {

This is the "Scoring" part of the code, Chrome says the error is on the first line - can you please suggest what exactly could be wrong?

If (NumberCorrect === '5') {
   alert('Congratulations, you answered all questions correctly and received a Gold Medal!');
 } else if (NumberCorrect === '4' || NumberCorrect === '3'){
      alert('Congratulations, you received a Silver Medal!');
 } else if (NumberCorrect === '2'){
      alert('You received a Bronze Medal!');
 } else {
      alert('You did not receive any medals');           
 }

Thank you in advance!

2 Answers

Hi Michael,

Simple. Just change the 'If' to 'if' (notice the capitalization). It is case sensitive.

Michael L
Michael L
2,482 Points

Thank you Raouf - that helps!

I also found that I forgot a couple of closing curly braces in the previous section of code (that I did not paste here).