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

Jason Styron
PLUS
Jason Styron
Courses Plus Student 955 Points

Create a variable with a string challenge task 2

don't understand how to use document.write function to print the contents of player variable to the page, in the challenge create a variable with a string

1 Answer

var player = 'Jasmine';

document.write(player);

In example above, we create a variable with the var keyword and give it a name called player. We then tell this variable to have the string value of Jasmine by usong the assignment operator (=).

The document.write() is a function that can take any variable and write it to the document. In the case we provide it with the variable name that containes a value. This value will be printed to the page.

I hope that made sense ?