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

Glenn Rubin
Glenn Rubin
1,799 Points

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

Glenn Rubin
Glenn Rubin
1,799 Points

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

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