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 trialJonathan Pearson
Courses Plus Student 6,704 PointsHaving 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
10,663 PointsYour 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>");
}
Richard Barkinskiy
10,663 PointsMake 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!
Jonathan Pearson
Courses Plus Student 6,704 PointsGot it to work thanks!
Richard Barkinskiy
10,663 PointsEither update the var name to "answer" or in your "if" statement, change "answer" to "question"
Stefan Osorio
16,419 PointsThat'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.
Jonathan Pearson
Courses Plus Student 6,704 PointsI tried switching them around but it still wont work.
Stefan Osorio
16,419 PointsYou 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
Jonathan Pearson
Courses Plus Student 6,704 PointsJonathan Pearson
Courses Plus Student 6,704 PointsThe document write part is still not working. Very strange