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

David Sheridan
David Sheridan
8,579 Points

How do I store the answer in the variable?

I'm not sure why this isn't working, can anyone see any error or is my logic off?

scripts.js
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>

4 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Challenges are picky... and I mean super picky. Capitalize the "W" in What. "What day is it?" will pass. "what day is it?" will fail.

Could you make a

console.log(answer);

to see if you can see your answer in the browser's console ?

alastair cooper
alastair cooper
30,617 Points

Your code works fine in my browser.

Make sure that your browser is not disabled from giving alerts. Make sure that scripts is in the same file as the html.

check the console and query 'answer'. It gives the answer I gave in the prompt when I tried it.

Cheers

Alastair

When you execute the prompt() command in the browser, the value you input into the text box stores it into the variable 'answer'.

When you write the command

document.write(answer);

for instance, it will print the stored value of 'answer' in the document.