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 trialpamela guy
Courses Plus Student 4,311 PointsUse 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?
var answer;
var answer = prompt(What day is it?);
<!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
28,558 PointsWhen 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.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
12,314 PointsYou`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?");
Gilbert Francis
873 PointsThat won't work unless you get rid of the second word answer and the ;