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

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