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 prompt() method to ask the user "What day is it?" and store the result in the answer variable. I am stuck with e

I wrote:

var answer prompt ("What is your name?"); var answer = prompt("What is your name"); alert(answer);

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

4 Answers

Hi Heriberto,

You have missed question ? inside prompt message.

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

Thank you so much! i didn't realize it

Great, it happened to us all the times.

Happy Coding! :)

P.S: Please make sure to mark best answer that solve your question if possible and also prevent others from similar mistakes.

Something else which should be causing a problem is declaring the answer variable twice. You either need to rename the second one or if you want to reuse the answer variable then delete the second var keyword.

Hope this helps a little.

Shruti Kapoor
Shruti Kapoor
2,388 Points

var answer;

prompt("What day is it?" );

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

document.write (answer);

var answer;

//prompt("What day is it?" ); //No need to prompt twice

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

document.write (answer);