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.
Alanis Chua2,830 Points
function instead of document.write
why using the print() and call the function later on instead of only document.write
Hi Alanis, the print() function is more efficient because when calling the function you're setting the innerHTML property of a certain 'div' in the DOM (based on its class or id) to the string you'll normally just write out on the document object(document.write()). And since you wrap it all in a function that means its reusable, whenever you want to print out something on the web page, you just call the function passing in an argument(string, array, variable etc) to print it out.