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 Object-Oriented JavaScript (2015) Constructor Functions and Prototypes Making the UI Work

Ran Yehushua
Ran Yehushua
5,908 Points

Why doesn't the renderInElement method in playlist.js "return" the list.innerHTML value?

I see that the for loop within the renderInElement method is calling the toHTML method that is defined in the song.js doc, that toHTML is returning the HTML for each song one at a time. Why isn't the list.innerHTML being returned with the "return" keyword like it is in the toHTML method? Does the innerHTML method do this returning on its own?

1 Answer

Hi Ran,

renderInElement is setting the inner HTML of the passed-in list, which is the ordered list from index.html.

If, instead, this function were written to return a big string containing all of the list items - created by toHTML, we would then still have to set the inner HTML of the ordered list at some point. We would then need to consider renaming renderInElement to something else, as it would no longer be doing what its name implies.

Ran Yehushua
Ran Yehushua
5,908 Points

That its clear. Thanks for the reply!