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

Why is my quiz not working?

Here is my code. I don't even get the first prompt asking for an answer to the first question.

// Ask 5 questions // Keep track of right answers // Provide final message letting user number number of questions right // Rank. 5 is gold crown, 3-4 is silver crown, 1-2 is bronze crown, 0 no crown

var correct = 0;

var answerOne = prompt("What is the name of Harry Potter's owl?"); if (answerOne.toUpperCase() === "HEDWIG") { correct += 1; } var answerTwo = prompt("Who is Harry's best friend?"); if (answerTwo.toUpperCase() === "RON") { correct += 1; } var answerThree = prompt("What is Hermione's last name?"); if (answerThree.toUpperCase() === "GRANGER") { correct += 1; } var answerFour = prompt("What class does Snape teach?"): if (answerFour.toUpperCase() === "POTIONS" ) { correct += 1; } var answerFive = prompt("What does Tom Riddle's full name unscramble to spell?") if (answerFive.toUpperCase() === "I AM LORD VOLDEMORT") { correct += 1; }

alert("You got " + correct + " questions right!");

if (correct === 5) { alert("You have earned the Gold Crown!"); } else if (correct > 2) { alert("You have earned the Silver Crown!"); } else if (correct > 0) { alert("You have earned the Bronze Crown!"); } else { alert("You have earned the Wood Crown! NOOB!!"); }

I would do have your conditional statement after converting the answer to uppercase: var correct = 0; var answerOne = prompt("What is the name of Harry Potter's owl?"); answerOne = answerOne.toUpperCase(); if (answerOne==="HEDWIG") {correct += 1}

and so on.

1 Answer

Frankie Snavely
Frankie Snavely
5,184 Points

There are two syntax errors in your code.

var answerFour = prompt("What class does Snape teach?"):

There should be a semicolon at the end, not a colon.

var answerFive = prompt("What does Tom Riddle's full name unscramble to spell?")

There should be a semicolon at the end of this statement as well.

Once both of these were corrected, your quiz worked just fine for me.

Wow! Can't believe I missed that! Such small stuff! Thank you very much!