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 Adding Data to Arrays

Confused on the function - function print(html) { document.write(html); }

Hi, i am still a bit confused to how does this ode works - function print(html) { document.write(html); }

Why i am confused is that, I understand the print() method "prints" the contents of the current window. but what is "html" in this case? is it another method?

Thanks in advance

2 Answers

Steven Parker
Steven Parker
231,236 Points

In this case "html" is just the parameter name that stands for whatever you pass when you call the "print" function. All this function does is pass the same thing on to the "document.write" function, so effectively "print" is just another name for "document.write".

Thanks Steven Parker for your answer. just to confirm can you also just write the same function but without the "html"? like below? function print() { document.write(); }

or do we need it in order to run document.write() ?

Steven Parker
Steven Parker
231,236 Points

You must have some parameter name, it cannot be blank. But it doesn't have to be "html", you can use any name you want.

Thanks! Steven Parker it all makes sense now!