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 Create a variable with a string

What is wrong with my code ?

Use the document.write() function to print the contents of the player variable to the page.

app.js
var player="Jasmine";
document.write('player');
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="app.js"></script>
</body>
</html>

You don't need quotes around the variable when you call it in document.write

Double quotes ? around player in the doc.write() ?

5 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

document.write('player');, just write the string 'player'; use document.write(player); will write the value of the variable.

Thanks i wasn't too far off was I?

William Li
William Li
Courses Plus Student 26,868 Points

hah, nay, these concepts can be a bit confusing when you learn them for the first time.

True thanks for the help mate

It 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.

hahah nope... I've made that same mistake. Probably won't be the last time it happens too :)

lol computers are unforgiving :(

Danielle Hill
Danielle Hill
26,062 Points

Hi 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().

I was confused myself!! Thanks guys.