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 Making Decisions in Your Code with Conditional Statements The Conditional Challenge Solution

Why is it always 0 of 5 correct?

/* 
  1. Store correct answers
   - When quiz begins, no answers are correct
*/

let correct = 0;

// 2. Store the rank of a player

let rank = "none";
// 3. Select the <main> HTML element

const main = document.querySelector('main');


/*
  4. Ask at least 5 questions
   - Store each answer in a variable
   - Keep track of the number of correct answers
*/

const answer1 = prompt("What is the 1st number?");
 if ( answer1.toUpperCase() === 'one' ) { correct += 1;
                                       }
const answer2 = prompt("What is the 2nd number?");
  if ( answer2.toUpperCase() === 'two' ) { correct += 1;
                                       }
const answer3 = prompt("What is the 3rd number?");
if ( answer3.toUpperCase() === 'three' ) { correct += 1;
                                       }
const answer4 = prompt("What is the 4th number?");
 if ( answer4.toUpperCase() === 'four' ) { correct += 1;
                                       }
const answer5 = prompt("What is the 5th number?"); 
  if ( answer5.toUpperCase() === 'five' ) { correct += 1;
                                       }


/*
  5. Rank player based on number of correct answers
   - 5 correct = Gold
   - 3-4 correct = Silver
   - 1-2 correct = Bronze
   - 0 correct = No crown
*/

if ( correct === 5 ) {
  rank = "Gold"; 
}
else {
  rank = "None :(";
}



// 6. Output results to the <main> element

main.innerHTML = `<h2> You got ${ correct } out of 5 questions correct. Rank ${rank} </h2>`;

1 Answer

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Rohald van Merode
Treehouse Staff

Hi Glenn Rubin 👋

You'll want to have a look at your conditionals. Currently you're converting the given answer to an all uppercase string and you're comparing it to a lowercased string. The condition will therefor never be true and the correct variable won't be increased on a correct answer 🙂

Hope this helps

Thanks! I was going crazy looking at the syntax and everywhere else!

It's so obvious now that you point that out.