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 Simplify Repetitive Tasks with Loops The Refactor Challenge, Part 2

Ernest Son
Ernest Son
13,532 Points

no return for the print function?

just wondering why there is no "return message" in the print function.....

1 Answer

Lets break down the print function used and maybe we can find out why:

function print(message) {
  var outputDiv = document.getElementById('output');
  outputDiv.innerHTML = message;
}

outputDiv.innerHTML = message;

is the key to your question. .innerHTML sets/returns the HTML value/content of the element. So the print function does return a value but by using innerHTML. This will return the HTML value of the argument that is set by the parameter message in our function. I hope this helps. if you want to learn more about innerHTML take a read.

https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML

I hope this helps.