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

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 ?