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) Storing and Tracking Information with Variables Capturing Visitor Input and Writing It to the Page

Use 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.

scripts.js
var answer ;
prompt ("What day is it?");
var answer = prompt ("What day is it?")
alert (answer) ;
document.write(answer);
index.html
<!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

var 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!

Michael,

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.

You're close, it might not accept the answer because there is no need for the alert in the challenge!

Sorry mikes02! First time answering a question on here! I'll make sure to explain more thoroughly!

No worries, it's just good practice, it also helps people learn instead of just being provided the correct answer :D

Stanley Thijssen
Stanley Thijssen
22,831 Points

Hi 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

Pass 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);