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 Solution

Kevin Jarvis
Kevin Jarvis
3,726 Points

Quiz aborts after first two questions

My quiz always aborts after the first two questions. The third prompt is never displayed, and I can't figure out why. There are also no results displayed.

Here is my code...

var correctPoints = 0;


/* QUESTIONS */

var answer1 = prompt("1. Which tube line is silver in color?");
if ( answer1.toUpperCase() === "JUBILEE" ) {
  correctPoints += 1;
}

var answer2 = prompt("2. Which borough includes the Houses of Parliament and Buckingham Palace?");
if ( answer3.toUpperCase() === "WESTMINSTER" ) {
  correctPoints += 1;
}

var answer3 = prompt("3. In which travel card zone is Camden Town station?");
if ( answer3.toUpperCase() === "2" ) {
  correctPoints += 1;
}

var answer4 = prompt("4. In which neighbourhood can you find the famous Electric Avenue?");
if ( answer4.toUpperCase() === "BRIXTON" ) {
  correctPoints += 1;
}

var answer5 = prompt ("5. At which National Rail station can you interchange with the Bakerloo, Hammersmith & City, Circle and District lines?");
if ( answer5.toUpperCase() === "PADDINGTON" ) {
  correctPoints += 1;
}


/* RESULTS */

document.write("<p>You got " + correctPoints + " questions correct!<p>");

if (correctPoints === 5) {
  document.write("<p>You win a <strong>gold</strong> crown!</p>");
} else if (correctPoints >=3) {
  document.write("<p>You win a <strong>silver</strong> crown!</p>");
} else if (correctPoints >0) {
  document.write("<p>You win a <strong>bronze</strong> crown!</p>");
} else {
  document.write("<p>You win a no crown :(</p>");
}

Edited to format code.

2 Answers

In var answer2 you refer to answer3 instead of answer2

Kevin Jarvis
Kevin Jarvis
3,726 Points

Ah yes, simple but stupid. Thanks for spotting it!

No problem. Please mark best answer to indicate the problem was solved.