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

Questions not adding up correctly for some reason.

For some reason it never displays gold, anyone know why?

let correctAnswer = 0;

let questionOne = prompt("is Earth the 3rd planet from the sun?"); if(questionOne.toUpperCase() === "YES"){ correctAnswer += 1; }

let questionTwo = prompt("Have humans landed on the moon?"); if(questionTwo.toUpperCase() === "YES"){ correctAnswer += 1; }

let questionThree = prompt("Which planet is closest to the sun?"); if(questionThree.toUpperCase() === "MERCURY"){ correctAnswer += 1; }

let questionFour = prompt("Which planet is the biggest in our solar system?"); if(questionFour.toLowerCase() === "JUPITER"){ correctAnswer += 1; }

let questionFive = prompt("which planet is the smallest in our solar system?"); if(questionFive.toUpperCase() === "PLUTO"){ correctAnswer += 1; }

if (correctAnswer === 5){ alert("You were awarded a Gold Medal!"); } else if(correctAnswer === 3 || correctAnswer === 4 ){ alert("You were awarded a Silver Medal!"); } else if(correctAnswer === 2 || correctAnswer === 1 ){ alert("You were awarded a bronze Medal!"); } else { console.log("Sorry you got zero correct"); }

2 Answers

Cameron Childres
Cameron Childres
11,818 Points

Hi Vahe,

It's because your fourth question is being converted to lower case then is compared to an upper case string. Easy to miss! Switch questionFour.toLowerCase() to questionFour.toUpperCase() and it should behave as expected.

Hello Cameron, got it thank you so much!