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 trialTim McKyer
10,989 PointsWhat is wrong with my code ?
Use the document.write() function to print the contents of the player variable to the page.
var player="Jasmine";
document.write('player');
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<script src="app.js"></script>
</body>
</html>
Tim McKyer
10,989 PointsDouble quotes ? around player in the doc.write() ?
5 Answers
William Li
Courses Plus Student 26,868 Pointsdocument.write('player');
, just write the string 'player'; use document.write(player);
will write the value of the variable.
Tim McKyer
10,989 PointsThanks i wasn't too far off was I?
William Li
Courses Plus Student 26,868 Pointshah, nay, these concepts can be a bit confusing when you learn them for the first time.
Tim McKyer
10,989 PointsTrue thanks for the help mate
Paul Jackson
8,943 PointsIt should look like this:
var player = "Jasmine"
document.write(player);
You don't have to put quotes around a var you've created when calling it.
Paul Jackson
8,943 Pointshahah nope... I've made that same mistake. Probably won't be the last time it happens too :)
Tim McKyer
10,989 Pointslol computers are unforgiving :(
Danielle Hill
26,062 PointsHi Timothy. Paul is right. When you include quotes, JavaScript interprets the text inside as a string, not a variable. Checkout the Storing and Tracking Information with Variables video around 1:22. You can see Dave store a variable and call it in document.write().
imtrying
19,943 PointsI was confused myself!! Thanks guys.
Paul Jackson
8,943 PointsPaul Jackson
8,943 PointsYou don't need quotes around the variable when you call it in document.write