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

I am getting an unexpected token else on line 30 of my code. I don't see what the problem is, can anyone point it out?

//number of answers correct
var correct = 0;

// here are the 5 questions
var question1 = prompt("True or false, school begins at 8:00 am?"); 
if(question1.toUpperCase() === "TRUE") {
  correct += 1;
}
var question2 = prompt("What period is 8th grade lunch?");
if(question2 === "7th") {
  correct += 1;
}
var question3 = prompt("What time do we get to school?");
if(question3 === "7:45") {
  correct += 1;
}
var question4 = prompt("What time do we go home?");
if(question4 === "4:15") {
  correct += 1;
}
var question5 = prompt("What is my favorite day?");
if(question5.toUpperCase() === "SATURDAY") {
  correct += 1;
}
document.write("Congratulations, you finished the quiz! You got " + correct + " answers correct!");

// awarding the crowns
if(correct === 5); {
  document.write("Congratulations, you get the gold crown!")
} else if (correct === 4 || correct === 3) {
  document.write("Good job, you get the silver crown!")
} else if (correct === 1 || correct === 2); {
  document.write("Well done, you get the bronze crown!")
} else {
  document.write("Try again next time.")
}

1 Answer

Dave StSomeWhere
Dave StSomeWhere
19,870 Points

You've got 2 semi-colons that shouldn't be there

// awarding the crowns
if(correct === 5); {  // Remove semi-colon
  document.write("Congratulations, you get the gold crown!")
} else if (correct === 4 || correct === 3) {
  document.write("Good job, you get the silver crown!")
} else if (correct === 1 || correct === 2); { // Remove semi-colon
  document.write("Well done, you get the bronze crown!")
} else {
  document.write("Try again next time.")
}