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

For some reason, my code is not adding the answer and providing me the winning crown. Help!

I checked my code and I answer all the correct answers. But no matter what, it says I answered 0 answers correct. Can someone help?

// quiz begins with no answers

var correct = 0;

// ask the questions

var answer1 = prompt("Name the fastest Thundercat?"); if (answer1.toUpperCase() === "Cheetara") { correct += 1; }

var answer2 = prompt("Who is the pretiest Smurf?"); if (answer2.toUpperCase() === "Vanity") { correct += 1; }

var answer3 = prompt("The ememy of the Autobots"); if (answer3.toUpperCase() === "Decepticons") { correct += 1; }

var answer4 = prompt("He-man says. \"for the power of...\""); if (answer4.toUpperCase() === "Greyskul") { correct += 1; }

var answer5 = prompt("The name of the pig in love with a frog.. is Ms. ___"); if (answer5.toUpperCase() === "Piggy") { correct += 1; }

//ouput results

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

//rank

if ( correct === 5 ) { document.write("<p><strong>You are the winner of the GOLD CROWN!</strong></p>"); } else if (correct >= 3) { document.write("<p><strong>You are the winner of the Silver Crown!</strong></p>"); } else if (correct >= 2) { document.write("<p><strong>You are the winner of the bronze Crown!</strong></p>"); } else { document.write("<p><strong>You are a loser</strong></p>"); }

2 Answers

Hi Bacchus,

A sample from your code:

(answer1.toUpperCase() === "Cheetara"

It looks like you have mistaken "Capitalization" for "UpperCase." UpperCase will capitalize all letters of the answer, not just the first. So, to get a match below you need "CHEETARA" instead of "Cheetara."

Hope this helps.

that was it! WOW! it is amazing. Always learn something new!

Thanks my friend =)

Thanks! Yes, you made it easier to add multiple conditional statements( &&, ||).