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 Making Decisions in Your Code with Conditional Statements The Conditional Challenge Solution

Code not working at all

I followed the instructions and even corrected my code to look exactly like Guil's at the end of the video, but the code still isn't working. When trying to test if it works, I receive an error saying "Uncaught SyntaxError: Unexpected end of input." Can someone please help?

Below is the code that was written:

/* 
  1. Store correct answers
   - When quiz begins, no answers are correct
*/
let correct = 0;

// 2. Store the rank of a player
let rank;

// 3. Select the <main> HTML element
const main = document.querySelector('main');

/*
  4. Ask at least 5 questions
   - Store each answer in a variable
   - Keep track of the number of correct answers
*/
const answer1 = prompt("What is the color of the sky?");
if ( answer1.toUpperCase() === 'Yellow') {
  correct += 1;
}
const answer2 = prompt("What is the color of the ocean?");
if ( answer2.toUpperCase() === 'Blue') {
  correct += 1;
  const answer3 = prompt("What is a device that tells time?");
if ( answer3.toUpperCase() === 'Clock') {
  correct += 1;
  const answer4 = prompt("When water falls from the sky, what's that called?");
if ( answer4.toUpperCase() === 'Rain') {
  correct += 1;
  const answer5 = prompt("What color is a paper clip?");
if ( answer5.toUpperCase() === 'Silver') {
  correct += 1;

/*
  5. Rank player based on number of correct answers
   - 5 correct = Gold
   - 3-4 correct = Silver
   - 1-2 correct = Bronze
   - 0 correct = No crown
*/
if ( correct === 5 ) {
rank = 'Gold';
} else if ( correct >= 3) {
rank = 'Silver';
} else if ( correct >= 1) {
rank = 'Bronze';
} else {
rank = 'None :(';
}

// 6. Output results to the <main> element
main.innerHTML = 
   `<h2>You got ${correct} out of 5 questions correct.</h2>
    <p>Crown earned: <strong>${rank}</strong></p>
`;

1 Answer

Look specifically at this line:

if ( answer2.toUpperCase() === 'Blue') {
  correct += 1;
  const answer3 = prompt("What is a device that tells time?");
if ( answer3.toUpperCase() === 'Clock') {
  correct += 1;
  const answer4 = prompt("When water falls from the sky, what's that called?");
if ( answer4.toUpperCase() === 'Rain') {
  correct += 1;
  const answer5 = prompt("What color is a paper clip?");
if ( answer5.toUpperCase() === 'Silver') {
  correct += 1;

You are missing multiple closing braces.

I see it now. Can't believe that I missed that. Thank you so much for the help!!

Frank Kynard
Frank Kynard
6,958 Points

I did the samething but only to 1 of them. Thanks for the help. When I seen this I went back to check my own code and what do you know I did'nt have a } . New respect for coders.