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

why is this line of code not working? (Javascript basics challenge)

Hello I am doing a challenge on the javascript basics, I wrote this code down but I have no idea why it does not work on the preview. What I thought it should have done is once the answer is given then the 1st alert should pop up but nothing shows up. why? (FYI I tried the document.write aswell instead of alert.)

var q1 = prompt("what country is the lion's natural habitat?");

if ( q1 === Africa) {
alert("Hey great you got that right!");
} else {
alert("Sorry, that's wrong try to get the next one!");
}

1 Answer

Africa should be in quotes

Hey thanks for your answer I ended looking into it a bit more and I found out what I needed to do. what I eventually wanted to do was to get the Africa into a toUpperCase so that no matter what the user's input as long as the answer is Africa it would be right but I was stuck on getting the first alert to even show up. Your answer did help out though either way it did needed quotes.