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

John O'Connell
John O'Connell
2,022 Points

No matter the answers, I get 5 out of 5.

Here is my code...

//quiz begins var correct = 0;

//questions

var answer1 = prompt("name?"); if (answer1.toUpperCase() === 'JOHN'); { correct += 1; }

var answer2 = prompt("best programming langauge?"); if (answer2.toUpperCase() === 'JAVASCRIPT'); { correct += 1; }

var answer3 = prompt("where you live?"); if (answer3.toUpperCase() === 'CHICAGO'); { correct += 1; }

var answer4 = prompt("How you get to work?"); if (answer4.toUpperCase() === 'TRAIN'); { correct += 1; }

var answer5 = prompt("Favorite beer?"); if (answer5.toUpperCase() === 'REVOLUTION'); { correct += 1; }

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

//output rank

if (correct === 5) { document.write("<p><strong>you get a gold crown!</strong></p>"); }

else if (correct >= 3){ document.write("<p><strong>silver crown</strong></p>"); } else if (correct >=1){ document.write("<p><strong>bronze</strong></p>"); } else { document.write("<strong><p>booooo</strong></p>");

}

John O'Connell
John O'Connell
2,022 Points

also that formatted weird, the "//quiz begins" and "var correct =0; " are on separate lines

3 Answers

Ben Schroeder
Ben Schroeder
22,818 Points

I think the problem is coming from the semicolons you're putting after the if conditions.

Instead of this:

if (answer1.toUpperCase() === 'JOHN'); { correct += 1; }

You want this:

if (answer1.toUpperCase() === 'JOHN') { correct += 1; }
Jacques Retief
Jacques Retief
954 Points

John, have you found out how to print your code to screen like Ben did?

Thanks! I was wondering why!