Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge Solution

Ryan Timm
Ryan Timm
Front End Web Development Techdegree Student 4,569 Points

My answers aren't adding up on the Conditional Code Challenge


After having some trouble with this challenge, I went back and followed the teachers solution to see if I could get it to work. The quiz runs, but my answer's are not adding up at all. Could someone please look at my code and point me in the right direction?

// quiz begins, no answers correct
var correct = 0;

//ask questions
var answer1 = prompt("Name our 44th President.");
if (answer1.toUpperCase() === 'President Obama') {
   correct += 1; 
var answer2 = prompt("Name the President during the Gulf War?");
if(answer2.toUpperCase() === 'President Bush') {
  correct += 1;
var answer3 = prompt("Name the President who had polio?");
if(answer3.toUpperCase() === 'President Roosevelt') {
  correct +=1;
var answer4 = prompt("Name the President who could not tell a lie?");
if(answer4.toUpperCase() === 'President Washington') {
  correct += 1; 
var answer5 = prompt("Name our most current President who was impeached.");
if(answer5.toUpperCase() === 'President Clinton') {
  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!</strong></p>");
} else if ( correct >= 3 ) {
  document.write("<p><strong>You earned a silver crown.</strong></p>");
} else if (correct >= 1 ) {
  document.write("<p><strong>You earned a bronze crown.</strong></p>");
} else {
  document.write("<p><strong>No Crown for you. You need to study.</strong></p>");

2 Answers