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 variaable

Challegne Task 2 of 3

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

2 Answers

Hey Troy! Your close, you have create the variable "answer". Now you simply want to store whatever the user inputs in the prompt to that variable. The code should look like this:

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

Yes I've tried this but just to be sure do you mean I have to create another var answer on another line? because your response will cancel and/or stop line one from passing

Hey again Troy! No you do not create the variable again by saying answer = prompt("What day is it?). It simply assigns the value of the prompt to the variable that you already created on line 1. You cannot create a variable just by saying test = "something". You must use the var keyword. Secondly your saying that my response will stop line 1 from passing?? If this is the case you have simple made a typo somewhere, try to just copy the code i have given you, it will pass. Please write back if you still need help!

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

This is what I did even though I used an assigned the = assignment the first line passes also the script runs the prompt() but I get an error message You did not add the What day is it to the prompt function

Thank you for your help Behar and your advice on how to use variables I will keep this in mind I see now I will have to call call you the Javascript Guru your code worked for me

Howdy!

The single problem is the way you declare variables. The correct way to declare a variable is this:

var (variableName);
// or, if you want to assign a value to it directly
var (variableName) = (variableValue);

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

The text between the parentheses (variableName and variableValue) is just a template. You want to use this "template" without parentheses.

Hope it helped!