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

Jonathan Pearson
PLUS
Jonathan Pearson
Courses Plus Student 6,704 Points

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

Richard Barkinskiy
Richard Barkinskiy
10,663 Points

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>");
}
Jonathan Pearson
Jonathan Pearson
Courses Plus Student 6,704 Points

The document write part is still not working. Very strange

Richard Barkinskiy
Richard Barkinskiy
10,663 Points

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!

Richard Barkinskiy
Richard Barkinskiy
10,663 Points

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

Stefan Osorio
Stefan Osorio
16,419 Points

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.

Stefan Osorio
Stefan Osorio
16,419 Points

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