Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics Making Decisions in Your Code with Conditional Statements The Conditional Challenge Solution

Sidney Smith
Sidney Smith
1,777 Points

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

Joseph Yhu
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Joseph Yhu
PHP Development Techdegree Graduate 47,172 Points

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.

Sidney Smith
Sidney Smith
1,777 Points

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

Frank Kynard
Frank Kynard
2,018 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.