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

Rebecca Jensen
Rebecca Jensen
11,580 Points

Script is not adding 1 to the variable

My prompts work for this challenge, but my correct answers don't add 1 to the variable "correct". Any insight as to what's wrong? Thanks!

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

//ask questions
var answerOne = prompt("What color is Rey's lightsaber?");
if (answerOne.toUpperCase() === "blue" ) {
  correct += 1;
} 
var answerTwo = prompt("What color is Windu's lightsaber?");
if (answerTwo.toUpperCase() === "purple" ) {
  correct += 1;
} 
var answerThree = prompt("What color is Yoda's lightsaber?");
if (answerThree.toUpperCase() === "green" ) {
  correct += 1;
} 
var answerFour = prompt("What color is Vader's lightsaber?");
if (answerFour.toUpperCase() === "red" ) {
  correct += 1;
} 
var answerFive = prompt("What color is Kylo's lightsaber?");
if (answerFive.toUpperCase() === "red" ) {
  correct += 1;
} 

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

//output rank 
if (correct === 5) {
  document.write("<p>You earned a <strong>gold</strong> crown!</p>");
} else if ( correct >= 3 ) {
  document.write("<p>You earned a <strong>silver</strong> crown!</p>");
} else if ( correct >= 1 ) {
  document.write("<p>You earned a <strong>bronze</strong> crown!</p>");
} else if (correct === 0 ) {
  document.write("<p>You did not earn a crown. :( </p>");
} 

2 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

you are trying to match upper-cased inputs to lower cased values. if you want to upper all your inputs, they need to be compared to upper-cased values to see if the words are equal. in this case, A does not equal a. you could of course lower the inputs as well, as long as you are comparing similar cases since differently-cased string compare as unequal.

Rebecca Jensen
Rebecca Jensen
11,580 Points

Aha! So I just changed the answers ("red" --> "RED") and it works now! (And you can still type in a lower case answer and get it correct.) Thank you!