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!

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

I don't understand why my code isn't working.......please help!!!!!!

The if, if-else, else conditional is making my code not run, and I don't understand why. It appears almost the same as Dave's, so I'm at a loss. Here is my code in its entirety:

var correctAnswer = 0;

var question1 = prompt("What animal has a rattle?"); if (question1.toUpperCase() === 'RATTLESNAKE') { correctAnswer += 1; }

var question2 = prompt("What animal has tusks?"); if (question2.toUpperCase() === 'ELEPHANT') { correctAnswer += 1; }

var question3 = prompt("What animal hibernates?"); if (question3.toUpperCase() === 'BEAR') { correctAnswer += 1; }

var question4 = prompt("What animal lives for more than 80 years?"); if (question4.toUpperCase() === 'PARROT') { correctAnswer += 1; }

var question5 = prompt("What animal has a shell on its back?"); if (question5.toUpperCase() === 'TURTLE') { correctAnswer += 1; }

document.write("You got " + correctAnswer + " questions correct.");

if (correctAnswer === 5) { document.write("<p>You get a Gold Crown</p>"); } else if (correct answer >= 3) { document.write("<p>Silver Crown</p>"); } else { document.write("<p>You don't know me at all.</p>"); }

2 Answers

Simple typo.

When you're checking to see what crown the user is getting, you accidentally put a space in between correct answer >= 3 it should be correctAnswer >=3

Thanks Juan! I don't know how long I tried to figure that out, I just wasn't seeing my mistake. Makes perfect sense now!