JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops The Refactor Challenge, Part 2

Alanis Chua
Alanis Chua
2,830 Points

function instead of document.write

why using the print() and call the function later on instead of only document.write

1 Answer

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.