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

Wendy Goodwin
Wendy Goodwin
2,676 Points

Score won't increase

My score variable will not increase and I cannot figure out why... help!

//quiz begins, no answer correct
var score = 0;

var answer1 = prompt("What is the color of the sun?");
if ( answer1.toUpperCase() === "yellow") {
  score += 1;
}

var answer2 = prompt("What day is today?");
if (answer2.toUpperCase() === "Tuesday") {
  score += 1;
}

var answer3 = prompt("Do you like to code?");
if (answer3.toUpperCase() === "yes") {
  score += 1;
}

var answer4 = prompt("Is your name Bill?");
if (answer4.toUpperCase() === "no") {
  score += 1;
}

var answer5 = prompt("Would you like another cup of coffee?");
if (answer5.toUpperCase() === "absolutely") {
  score += 1;
}

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


if (score > 2 ) {
  alert("You won the gold crown!");
  }  
else if (score <= 2 ) {
  document.write("sorry you didn't pass.");
}
Iain Diamond
Iain Diamond
29,379 Points

One problem I see is where you are using function toUpperCase(). If you type in 'yellow' and convert this to upper case the result will be "YELLOW". So your first if statement would work better as:

if ( answer1.toUpperCase() === "YELLOW") {...}

Hope this helps. iain

Wendy Goodwin
Wendy Goodwin
2,676 Points

yes!!! That fixed it. Thanks a bunch.

Hey Iain,

If you put your answer as an answer, we can upvote it and Wendy has the opportunity to mark it as best answer. =]

Iain Diamond
Iain Diamond
29,379 Points

Hi, Marcus, Thanks for the 'nudge'. :-)

I'll do that now, just for the practice.

iain

1 Answer

Iain Diamond
Iain Diamond
29,379 Points

One problem I see is where you are using function toUpperCase(). If you type in 'yellow' and convert this to upper case the result will be "YELLOW". So your first if statement would work better as:

if ( answer1.toUpperCase() === "YELLOW") {...}

Hope this helps. iain