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

Adam Kmet
Adam Kmet
1,039 Points

im stuck with storing variable

can anyone see my mistake please?

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

5 Answers

andren
andren
28,558 Points

You are missing a question mark at the end of your string, it should be:

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

The challenges are very picky about strings, they usually have to match the examples provided to the letter.

Pieter Bracke
Pieter Bracke
4,078 Points

That could also be the case. But see my answer 2 it is good practice to add ; after every line of code.

andren
andren
28,558 Points

It's good practice, sure, but not mandatory unless you are writing multiple statements on one line. It's not something that would cause the challenge to fail the code.

Pieter Bracke
Pieter Bracke
4,078 Points

yes ad ; to the end of your var line and it will work :)

so it should be : var answer= prompt("What day is it"); alert(answer);

Adam Kmet
Adam Kmet
1,039 Points

hi i just fixed it and believe or not the ; wasnt needed there the problem was that i was supposed to say what is your day? and I forgot to put the ? there hahahah...thank you for the quick answer

Adam Kmet
Adam Kmet
1,039 Points

yes youre right it is indeed a good practice to have ; there

I am going to agree with Andren. We are strongly encouraged to include ; at the end of lines. Most of the time it's not necessary. (but you will be shamed for not doing it) Oddly, not having a string EXACTLY the way the challenge presents it, will often cause a fail. Someone way smarter than me explained that js automatically puts ; in for you. (although it's not a guarantee) Not putting colons and commas in the correct places in lists will definitely break the code however.