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 Introducing Conditional Statements

Having issues with my document write

var question = prompt('What programming language is the name of a gem?');
if ( answer === 'Ruby' ) {
    document.write("<p>That's right!</p>");
}

I'm getting this message in the JavaScript console and i'm not sure what it means.

Uncaught ReferenceError: answer is not defined

4 Answers

Your final code, should look like this:

var question = prompt('What programming language is the name of a gem?');
if ( question === 'Ruby' ) {
    document.write("<p>That's right!</p>");
}

The document write part is still not working. Very strange

Make sure to enter "Ruby" exactly like that, with the capital "R" so that it will be true in the "if" statement. I just tested it and it works. Good luck!

Got it to work thanks!

Either update the var name to "answer" or in your "if" statement, change "answer" to "question"

That's because you are saving the input into the variable "question" in the first line - instead of the variable "answer", which is compared with "ruby" in line 2.

I tried switching them around but it still wont work.

You shouldn't switch them, but make them the same variable :)

Line 1: put result of prompt into variable "question"

Line 2: Compare the variable that you put the input into (in this case "question") with the desired result