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 trialJordan Blair
3,698 PointsUse the document.write method() to write the variable answer to the page. I need help.
need to figure out where I'm going wrong here.
var answer ;
prompt ("What day is it?");
var answer = prompt ("What day is it?")
alert (answer) ;
document.write(answer);
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<script src="scripts.js"></script>
</body>
</html>
3 Answers
Michael Horstman
15,432 Pointsvar answer;
answer = prompt ("What day is it?");
document.write(answer)
When you declared "var answer" you declared answer as a variable so instead of calling it as "var answer" again you can just call "answer". Also, there is not an alert part to the challenge, so I would get rid of that line because it could be throwing your answer off!
Stanley Thijssen
22,831 PointsHi Jordan,
Just create the answer variable and give it the prompt() function as value.
Then after that simply use the document.write() method to write it on the document like so:
var answer = prompt('What day is it?');
document.write(answer);
In your code your using var answer twice. Just use it once because you only need to define it once.
Second you are alerting the answer but this is not necessary
Lauren Sithole Gadyadza
6,659 PointsPass the variable containing the user's answer to document.write()
var mood = prompt("How are you today?");
document.write(mood); //User's response will print to the page
when i write the above answers i stillget a bummer saying i have my document.write at the wrong place and gives the above hint. help me out
Challenge Task 3 of 3 Use the document.write() method to write the variable answer to the page.
Bummer: It looks like you placed the document.write()
function in the wrong place.
scripts.js
index.html
prompt('What day is it?')
var answer = prompt('What day is it');
document.write(answer);
mikes02
Courses Plus Student 16,968 Pointsmikes02
Courses Plus Student 16,968 PointsMichael,
Rather than just providing the answer, it's typically encouraged to explain how you got there, it's more helpful to the original poster and to others who find this thread who are experiencing the same difficulty.
Michael Horstman
15,432 PointsMichael Horstman
15,432 PointsYou're close, it might not accept the answer because there is no need for the alert in the challenge!
Michael Horstman
15,432 PointsMichael Horstman
15,432 PointsSorry mikes02! First time answering a question on here! I'll make sure to explain more thoroughly!
mikes02
Courses Plus Student 16,968 Pointsmikes02
Courses Plus Student 16,968 PointsNo worries, it's just good practice, it also helps people learn instead of just being provided the correct answer :D