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 Solution

Casey Leonard
Casey Leonard
913 Points

I had to look at his solution to get myself started, but my first prompt won't even show up. Check for mistake?

//This is a Conditional Challenge from Treehouse by Casey Leonard

var right = 0;

var answer1 = prompt("What is the tallest animal in the world?"); if (answer1.toUpperCase() === 'GIRAFFE' ) { right +=1; } var answer2 = prompt("Does the male or female seahorse take care of their young?"); if (answer2.toUpperCase() ==='MALE') { right += 1; } var answer 3 = prompt("True or False, tortises can live to over 100 years old"); if (answer3.toUpperCase() ==='TRUE') { right += 1; } var answer4 = prompt("What is the fastest land animal?"); if (answer4.toUpperCase() ==='CHEETAH') { right += 1; } var answer5 = prompt("What animal is most like humans?"); if (answer.toUpperCase() === 'CHIMPANZEE') { right += 1; } if (right === 5) { document.write('You earned a gold crown!'); } else if ( right >=3) { document.write('You earned a silver crown.'); } else if (right >=2) { document.write('You earned a bronze crown.'); } else { document.write('No crown for you. You need to study.'); }

Oh, and this was all in orderly lines and spaces, but when I copy/paste on here, it is a bunched together in a hard to read format. How do I get my workspace to show on here like I can see it when I need help?

2 Answers

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Casey,

You have a syntax error: you declare a variable called 'answer 3' but you can't have spaces in your variable names.

Also, for answer5, your variable is called answer5 but you perform a conditional check on answer

Also to format your code snippets, use markdown. Treehouse puts a link to the markdown cheatsheet right under every question/answer box.

Cheers

Alex

Casey Leonard
Casey Leonard
913 Points

Thank you. Ugh. It is always those little things I don't catch. It works great now though!

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

It's always the way! You might find using a text editor that has syntax highlighting and inline error checking helps you with the the little typos we all make. Personally I use Visual Studio Code (and others swear by Atom) for most local code editing and it really helps when I make those sorts of errors.