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 trialJohn O'Connell
2,022 PointsNo 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>");
}
3 Answers
Ben Schroeder
22,818 PointsI 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; }
John O'Connell
2,022 Pointsthat did it! thanks!
Jacques Retief
954 PointsJohn, have you found out how to print your code to screen like Ben did?
louistan2
4,787 PointsThanks! I was wondering why!
John O'Connell
2,022 PointsJohn O'Connell
2,022 Pointsalso that formatted weird, the "//quiz begins" and "var correct =0; " are on separate lines