Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,383 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^^^. :)