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

peterson st gourdain
peterson st gourdain
931 Points

whats wrong

whats missing or wrong

app.js
var player = 'Jasmine'
var 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>

3 Answers

When passing a variable to a function, you don't wrap it in quotes. Quotes are used to denote a String. Also, the keyword var is used to denote a variable. When using methods on the document object (or any object instance) you don't need to declare it as a variable. So your two problems are: First, your variable isn't being passed to document.write(), the String "player" is; and second, you've created a syntax error in your second line;

var player = 'Jasmine'
document.write('player'); //This will write "player" to the document
document.write(player); //This will write "Jasmine" to the document
Matthew Long
Matthew Long
28,407 Points

You're missing a semicolon! If you check the console it should have told you something like "SyntaxError: missing ; before statement" and on what line.

Also, when you called the variable player you actually just called a string. So get rid of your quotes. One last thing.. you don't put var in front of document.write. This would be like making document.write(Jasmine) a variable so that you could call it later. You don't need to do this though.

var player = "Jasmine";
document.write(player);
Matthew OToole
Matthew OToole
22,946 Points

Both the above responses are correct^^^. :)