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 trialad19
1,827 PointsHow is "list" in the for loop connecting to the length of the array playList?
In the for loop, the loop is running as long as i < list.length, but I don't understand how the list is connecting to the amount of items in the playList array. How did this function determine that there were 6 items in the array?
4 Answers
ad19
1,827 PointsThanks Chris! I was confused on how "list" was connected to the amount of items in the array "playList". But now i understand. "list" only receives a value once the function is called. At the very end the program the function is called like this:
printList(playList);
Since the array "playList" was passed in the function, the function runs and .length will count the amount of items in playList.
KRIS NIKOLAISEN
54,972 PointsFor this video?
https://teamtreehouse.com/library/twodimensional-arrays
There the condition for the loop is i < songs.length where songs is passed in as a parameter.
If not could you provide a link?
ad19
1,827 PointsHi Kris,
Thanks for the response, its actually for this video: https://teamtreehouse.com/library/using-for-loops-with-arrays
chris robinson
2,818 PointsIt determines that there were six items in the array by the length property, length will return all values so when the code is ran the program will see and identify all that are in the collection