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 Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 1 Solution

Hunter G
Hunter G
6,612 Points

What does function print(message) do?!

what does the following code that Dave uses do exactly? what code is going into the (message) argument / parameter? I saw somebody else the same question as I am now a while back but didn't exactly receive a thorough answer. please help!

function print(message) {
document.write(message);
}

1 Answer

Steven Parker
Steven Parker
231,269 Points

It calls document.write to add the contents of message to the page.

The JavaScript program runs while the browser is loading the page, So after the program finishes, anything it has written to the page will appear on the screen.

For more info, see the MDN page for document.write.

Hunter G
Hunter G
6,612 Points

Thank you for your response Steven! I should've pasted all of the code from the challenge but yeah it makes sense now because I was wondering what the heck the ' print(html); ' line of code did because I didn't remember a print function being taught in the course. . tyvm!