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 trialnagamani palamuthi
6,160 Pointsplaylist code
if i use (playlist) instead of (list), as an argument for function printList , is it wrong coding? I tried it and it works.
see code above.
1 Answer
Benjamin Barslev Nielsen
18,958 PointsSince you declare the variable name of your array to be playList:
var playList = ...;
you need to call
printList(playList);
instead of using list. It would be wrong to write:
printList(list);
since you do not define a variable named list.
Aurelian Spodarec
10,801 PointsAurelian Spodarec
10,801 PointsWhere is the var playList? i don't see it anywhere in the code.
Stephen O'Dell
1,596 PointsStephen O'Dell
1,596 PointsI don't think that's what nagamani was talking about. I think we're talking about the parameter of the function printList on line 14.
Dave's words, around 5:30: This function takes an array as a parameter. Remember, a parameter is a variable that holds some value that's passed to the function. We'll pass an array to this function, so I'll give the parameter a simple name, like list.
So, he gave it the simple name list, but never declared list to be a variable of any sort. Then two lines later, we're using list.length in our test condition. But the array is named playList, not list.
For this function, how do we know the length of "list"? I can't find where it's defined or declared anywhere.
'''javascript function printList ( list ) { var listHTML = '<ol>'; for ( var i = 0; i < list.length; i += 1 ) { listHTML += '<li>' + list[i] + '</li>'; } '''