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 Solution

Hassan Noueilaty
Hassan Noueilaty
3,713 Points

Uncaught SyntaxError: Unexpected end of input

Hello,

I'm receiving the following error when I execute my code:

Uncaught SyntaxError: Unexpected end of input It's the '}' on line 47

Any help would be greatly appreciated!

Thank you,

-Hassan

// The Conditional Challenge
var playerRank = 'No crown';
var numCorrectQuestions = 0;


document.write("<p>Welcome to the Conditional Challenge!</p>");

// Questions 1-5
var question1 = prompt("How many days are in a week?");
if (question1 === 7) {
  numCorrectQuestions += 1;
}

var question2 = prompt("What is the current month?");
if (question2.toLowerCase() === 'february') {
  numCorrectQuestions += 1;
}

var question3 = prompt("What is the current year?");
if (question3 === 2017) {
  numCorrectQuestions += 1;

var question4 = prompt("What is the most widely used programming language today");
if (question4.toLowerCase() === 'javascript') {
  numCorrectQuestions += 1;
}

var question5 = prompt("What is the most popular search engine?");
if (question5.toLowerCase() === 'google') {
  numCorrectQuestions += 1;
}
// End of questions, display final message letting user know the number of questions he/she got right.
document.write("<p>You've answered " + numCorrectQuestions + " questions correct.</p>");

// Rank the player
if (numCorrectQuestions === 5) {
  playerRank = 'Gold Crown';
  document.write("<p>Your rank: " + playerRank + ".</p>");
} else if (numCorrectQuestions >= 3) {
  playerRank = 'Silver Crown';
  document.write("<p>Your rank: " + playerRank + ".</p>");
} else if (numCorrectQuestions >= 1) {
  playerRank = 'Bronze Crown';
  document.write("<p>Your rank: " + playerRank + ".</p>");
} else {
  playerRank = 'No Crown';
  document.write("<p>Your rank: " + playerRank + ".</p>");
}

3 Answers

Steven Parker
Steven Parker
231,275 Points

It's still looking for the closing brace to go with the open brace on line 20.

Also, remember that prompt returns a string, so even if the answer is a number, you'll need to put quotes around the one you compare with (or do a numeric conversion on the input).

You forgot to end one of the if statement's }.

Look through your code again :wink:

~Alex

Hassan Noueilaty
Hassan Noueilaty
3,713 Points

Ah! Thanks Alexander. I found the missing bracket.

Thanks Steven for pointing that out. I wasn't aware of that.