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 Tracking Multiple Items with Arrays Using For Loops with Arrays

ZoDo .
ZoDo .
13,135 Points

Hi, I have got a couple of questions about this video.

function print(message) { document.write(message); }

I do not understand the sense of this chunk of code and why it is necessary. Then

function printList( list ) { var listHTML = '<ol>'; for ( var i = 0; i < list.length ; i += 1 ) {
listHTML += '<li>' + list[i] + '</li>' } listHTML += '</ol>'; print(listHTML); }

In this function, we are using list as a parameter so the loop is running until it reach the list.length value, but when have we define it?

Thank you in advance to everyone..

ZoDo .
ZoDo .
13,135 Points

Oooook, I have probably solved the second one list is the parameter that is substituted with the playList value when we are using the function at the end of the code.

1 Answer

Steven Parker
Steven Parker
231,269 Points

:point_right: The first one seemed a bit odd to me also.

So print is basically just a shorthand for document.write. It just makes the code a bit more compact.

And as you suspected, printList converts a play list into an HTML ordered list and a set of list items to be displayed on the page.

ZoDo .
ZoDo .
13,135 Points

Thank you very much for your answer.