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 trialZoDo .
13,135 PointsHi, 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..
1 Answer
Steven Parker
231,275 PointsThe 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 .
13,135 PointsThank you very much for your answer.
ZoDo .
13,135 PointsZoDo .
13,135 PointsOooook, 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.