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 trialAlanis Chua
2,830 Pointsfunction instead of document.write
why using the print() and call the function later on instead of only document.write
1 Answer
Osaro Igbinovia
Full Stack JavaScript Techdegree Student 15,928 PointsHi 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.