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 trialHarrison Greeves
2,920 PointsMy 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
18,068 PointsThere 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.