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 trialEmily V
8,553 PointsNeeding help - Use the document.write() method to write the variable answer to the page
Not sure what I am doing wrong on this one. Thanks for any help!
var answer = prompt('What day is it?');
prompt ('What day is it?')
document.write(answer);
<!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
Kieran Barker
15,028 PointsThis is what your code should be:
var answer;
answer = prompt('What day is it?');
document.write(answer);
- The first line declares the
answer
variable without storing anything inside it. - The next line then updates the
answer
variable by storing inside it the string entered into the prompt (the first and second line could be shortened tovar answer = prompt('What day is it?')
but that isn't what this challenged has asked you to do). - The last line writes the string stored inside the
answer
variable to the page.
Billy Peacock
8,089 Pointsvar answer = prompt('What day is it?');
prompt ('What day is it?')
document.write(answer);
You don't need the second line as you have already declared the variable.
The first line sets the var answer to the prompt, then all you need to so is document.write and thats it!
var answer = prompt('What day is it?');
document.write(answer);
Kieran Barker
15,028 PointsYouβre right, but Task 1 of this challenge asks you to declare a variable without initialising it, then in Task 2 you update the contents of the variable, hence why Emily has tried to do it across two lines.