Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables Capturing Visitor Input and Writing It to the Page

Walika Pham
Walika Pham
1,802 Points

document.write() wrong placement Challenge task 3 of 3

Obviously I'm missing something. Where do I place this function?

scripts.js
var answer;
prompt("What day is it?");
var answer = prompt("Tuesday");
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>

2 Answers

You code for task 3 is ok. It is the code for task 2 where you have an issue. For task 2 you are to prompt "What day is it?" and store the result in answer. In your code you prompt "What day is it?" but don't store the result. Then you prompt "Tuesday" and store the result in a redeclared answer variable. There is no need to use var again once the variable has been declared. You just need to store the result of the first prompt as follows:

var answer;
answer = prompt("What day is it?");
document.write(answer);
Walika Pham
Walika Pham
1,802 Points

Thank you for your Answer! I have tried your suggestion and still getting the Bummer message: It looks like you placed the 'document.write()' function in the wrong place.

Walika Pham
Walika Pham
1,802 Points

I figured out!

I wasn't adding to the var answer, but adding additional lines. (see below)

var answer = prompt("What day is it?"); document.write(answer);