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

I am totally confused

The argument "list" that was put in the function print list, did not have any variable and i cant understand where it came from. I also do not understand why the length property was used on the "list" variable instead of the "playlist "array above. Lastly, I did not understand what print(listHTML); was doing there. is print a statement like alert or document.write.

3 Answers

Steven Parker
Steven Parker
231,269 Points

The argument "list" does have a variable when the function is called (on line 22). The variable is "playList".

Inside the function, the name "list" refers to that variable, so when "list.length" is used, it is the same thing as "playList.length".

And the "print" function is defined on lines 10-12. It is just a shorthand for "document.write".

Nicholas Wallen
Nicholas Wallen
12,278 Points

Then why not just write 'playList' instead of 'list', if they both refer to the same thing?

The guy teaching this video just breezes through without bothering to explain the why behind everything.

Steven Parker
Steven Parker
231,269 Points

The term "list" is actually a parameter name, which only acts as a placeholder in the definition for the argument that will be given to the method when it is called. The name of a parameter is not important, but it might be more confusing if it was the same as the argument that would be passed later.

i wish he would explain that in the video cause sometimes he just does things and im like wait a minute im confused.

Steven Parker
Steven Parker
231,269 Points

I believe "he" refers to Dave McFarland, the instructor in the video.

Mark Chang
Mark Chang
5,214 Points

actorly i think he explain very well, someone is hard to understand it because they might be aren't good at logic (you don't need to be really good at it but you need to learn some logic, like math)

pat barosy
pat barosy
6,759 Points

Steven, Thanks for your answer and explanation. I had the same question about "list". I used the playList variable instead of "list" and got the same output. I get it now though. It would be like putting x + y as parameters & then inserting 2 + 2 as your argument. A more generic name allows greater flexibility when changing arguments

Joel Stevenson
Joel Stevenson
4,137 Points

Yeah that's the thing, I think Dave lacked to explain/reinforce in this video the "Why?" aspect of using a placeholder instead of the original array. This may have been his most poorly explained video IMO.