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

I am not sure what I am doing wrong if anyone to help me that would be great.

I am working on the prompt() command.

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

Steven Parker
Steven Parker
229,786 Points

Only call prompt one time.

Calling it by itself asks the question, but throws away the answer. Just call it one time when you store the result in answer.

Thank you

This can be a little bit tricky if you aren't familiar with the syntax. When you make a variable declaration using the prompt method, the prompt window will appear and store the input directly in the variable for later use. So a run-down of what you are doing here is:

var answer;

This line declares the variable answer, but does not assign a value to it.

prompt ("What day is it?")

This line prompts the user for an input, BUT when the user clicks "OK" on the prompt, the input is thrown away.

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

This line declares the answer variable a second time and also prompts the user for input the same as the previous line, but this time it stores the input in a variable.

You are doing the same thing twice and have a bit of extra code in their. Given my summary, think critically about what each line is doing and which ones you really need to achieve the goal of this challenge.

Steven Parker
Steven Parker
229,786 Points

The second line does not declare the variable.

It just prompts the user but discards the resut.

Thank you