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

KRIS NIKOLAISEN
KRIS NIKOLAISEN
54,164 Points

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