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

Alex West
PLUS
Alex West
Courses Plus Student 1,878 Points

I keep getting a score of '0'. how do I fix my scoring section/what did I not do to my code?

/* QUIZ
Experimenting with if/else statements in a quiz format with a score */

//questions 1-5 prompt with an alert and score
var question1 = prompt("What color is the sky?");
  question1 = question1.toUpperCase();

if (question1 === 'BLUE') {
  alert("WOOT!");
  score += 10;
} else {
   alert('nope, it is blue.');     
   }

var question2 = prompt("How many legs does a horse have?");
question2 = question2.toUpperCase();

if (question2 === '4') {
    alert("WOOT!");
    score += 10;
} else {
  alert('nada, there are 4 legs.');
}

var question3 = prompt("What is a 'two-legged' ?");
question3 = question3.toUpperCase();

  if (question3 === 'HUMAN') {
    alert("WOOT!");
    score += 10;
  } else {
    alert("negative, it is a human.");
  }

var question4 = prompt("Name the best food at McDonald's.");
question4 = question4.toUpperCase();

if (question4 === 'FRENCH FRIES') {
  alert("WOOT!");
  score += 10;
} else {
  alert("nil, the correct answer is french fries.");        
}

var question5 = prompt("Can you ride a giraffe?");
question5 = question5.toUpperCase();

if (question5 === "YES") {
  alert("WOOT!");
  score += 10;
} else {
  alert("haha, yes you can!");
}

//score keeping
var score = 0;
  if (score === 50) {
    alert("Your score is " + score);
    alert("PERFECT SCORE");
  } else if (score <= 40) {
    alert("Your score is " + score);
    alert("GOOD");
  } else if (score <= 30) {
    alert("Your score is " + score);
    alert("OK");
  } else if (score <= 20) {
    alert("Your score is " + score);
    alert("NOT GREAT");
  } else {
    alert("Your score is " + score);
    alert("YOU'RE KILLIN ME SMALLS!");
  }

1 Answer

Steven Parker
Steven Parker
229,670 Points

:point_right: Your program sets the score to 0 after all the questions have been asked.

On line 56 you have "var score = 0". You probably want to move this to the very top.

Also, when testing the various score levels you do a "less than or equal" (<=) comparison. You probably want "greather than or equal" (>=).

And you could save a few lines by doing the "your score is.." alert before you check the score range.

Finally, shouldn't the correct answer message be "WOOT! WOOT!"? Just one woot seems a bit under-enthusiastic.:smile:

Happy coding! :sparkles: