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

pamela guy
PLUS
pamela guy
Courses Plus Student 4,311 Points

Use the prompt() method to ask the user "What day is it?" and store the result in the answer variable

what is wrong with my code help please?

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

3 Answers

andren
andren
28,558 Points
  1. When you want to change the contents of a variable you should not include the var keyword, var is used to create a new variable, not to change an existing one. This is not something that will cause an issue in this task, but is something you should keep in mind for future reference, as it can lead to unexpected behavior in certain scenarios.

  2. Strings, which are used to represent arbitrary text, has to be wrapped in quotes, it cannot stand on its own like it does in your solution.

If you fix those two issues like this:

var answer; // answer is declared
answer = prompt("What day is it?"); // prompt results are assigned to answer

Then you code will work, though it's also worth mentioning that you can combine the two lines above into one line like this:

var answer = prompt("What day is it?"); // answer is declared and assigned on the same line
Jose Luis Jimรฉnez Sastre
Jose Luis Jimรฉnez Sastre
12,314 Points

You`re declaring variable twice. Variables are declaring once with var keyword and then you use it without var keyword. Everytime you declare a variable is similar to create it again.

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

That won't work unless you get rid of the second word answer and the ;