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

i have been doing a lot of the videos per day and have forgotten how to put document.write into the html body.

the question asks me to use the document.write function to print the player variable onto the page and i have forgotten how to do that.

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

if i'm not mistaken the document.write go inside the html tag <body> doucment.write() </body>

Justin Hicks
Justin Hicks
14,290 Points

Hello Troy Document.write() is JavaScript that must be written in the app.js file

If it was to be written in the index.html file it would need to be contained with in a script tag which is not recommended.

JavaScript is written in a .js file to avoid cluttering html and JavaScript together among many other reasons.

2 Answers

Steven Parker
Steven Parker
229,708 Points

Any function call is just the name of the function followed by parentheses. Any argument(s) passed to the function go between the parentheses:

title = "<h1>This is a title</h1>";
document.write(title);
Justin Hicks
Justin Hicks
14,290 Points

The body is the document object. So .write is a method on the document object. When you call document.write(); it’s 100% going to print out to the body because the body is part of the document object.

Just put in document.write(player); in the app.js file and you will see from that point it will click.