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 trialjohn larson
16,594 Pointshave I got this print function parameter passing thing right?
/*.........print function.......*/
function print(message) { /* to be printed passed to print(message) */
return document.getElementById("print").innerHTML = message;
/* innerHTML = message is passed to (message)
and then printed to the page */
}
2 Answers
jcorum
71,830 PointsYou use return when you want something back from your function, e.g., a value, . Take this example:
function square(x) {
return x * x;
}
You give the function a value, x, and you want it to return the square of that value.
But in your case, you didn't need any value back. You just wanted the function to print a message to the page.
jcorum
71,830 PointsIf you just want to display message on the page, then there's no need for the return. Just do it like this:
function print(message) {
document.getElementById("print").innerHTML = message;
}
This code assumes there is an element on the page with an id of print.
john larson
16,594 Pointsthere is an id of print on the page for my innerHTML, and I thought Dave was using a return but I looked again and he wasn't. I'm still foggy on when return is necessary. Thanks for your feedback.
john larson
16,594 Pointsjohn larson
16,594 PointsThanks j, I think I get it.