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 (Retired) Making Decisions with Conditional Statements The Conditional Challenge Solution

Harrison Greeves
Harrison Greeves
2,920 Points

My code won't run

// quiz begins, no answers correct yet
var correct = 0;

// asks questions
var answer1 = prompt("What is the capital of Spain?");
if (answer1.toUpperCase() === "MADRID") {
  correct += 1;
}
var answer2 = prompt("What colour is the sky?");
if (answer2.toUpperCase() === "BLUE") {
  correct += 1;
}
var answer3 = prompt("Who is the president of the United States?");
if (answer3.toUpperCase() === "DONALD TRUMP") {
  correct += 1;    
}
var answer4 = prompt("What sound does a dog make?");
if (answer4.toUpperCase() === "WOOF") {
  correct += 1;
}
var answer5 = prompt("Is this quiz good? Yes or no?");
if (answer5.toUpperCase() === "YES") {
  correct += 1;
}

// output results
document.write("<p>You got " + correct + " out of 5 questions correct.</p>");

// output rank
if (correct === 5) {
    document.write("<p><strong>You earned a gold crown! Congratulations!</strong></p>");
}
if (correct >= 3) {
    document.write("<p><strong>You earned a silver crown.</strong></p>");
}
if (correct >= 1 {
    document.write("<p><strong>You earned a bronze crown.Meh.</strong></p>");    
}

1 Answer

Justin Cantley
Justin Cantley
18,055 Points

There is a tiny syntax error in your code.

if (correct >= 1 {
    document.write("<p><strong>You earned a bronze crown.Meh.</strong></p>");    
}

You are missing a closing parenthesis after the 1 for your if statement.
An easy way to catch this is to check your console in the browser. It will alert you to errors like this.