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 trialOrion Ford
2,100 PointsI've been looking but cannot find the error within the code. JAVASCRIPT
Can someone look at this for me and see if my document.write is correct? I cannot figure it out at all.
var answer;
prompt("What day is it?");
var answer = prompt("What day is it?");
alert(answer)
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
Unsubscribed User
Front End Web Development Techdegree Student 33,900 PointsHi Orion,
your document.write is correct, but you have a few unnecessary / problematic repetitions before that...
You declare 'var answer' twice (line 1 and 3 ) which should not be done. If you have declared a variable you can use it and reassign it any time by just using its variable name, like:
var number;
number = 5;
Then also you used the prompt command twice with the same message, which means the prompt message box will appear twice - first time without storing anything and the second time storing the variable.
Since you want to store the variable you can delete the first prompt command on line 2, and also the first variable declaration on line 1 (because you declare it again on line 3).
So basically: Delete line 1 and 2 and you are fine.
Hope that helps.
Happy coding!
Nils
PS: You can upvote my post and/or mark as "best answer" (at the bottom of my post) if it helped you. :-)
Unsubscribed User
Front End Web Development Techdegree Student 33,900 PointsAnother thing I just noticed when reviewing the code challenge...
You also have an unneccessary alert command on line 4. The code challenge just asks for the document.write command so you can/have to delete the alert command if you want to pass the code challenge.
So in the end you only have two lines.
Orion Ford
2,100 PointsOrion Ford
2,100 PointsThanks tons!