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 trialNijad Kifayeh
6,092 PointsCode correction
Just wanted to correct some of the code shown in the video. Specifically, Dave initially creates the variable (array) playList, but incorrectly refers to it in the functions as list; the correct code therefore is:
var playList = [
'A',
'B',
'C' ] ;
function print( message ) {
document.write( message ) ; }
function printList( list ) {
var listHTML = '<ol>' ;
for( var i = 0 ; i < playList.length ; i++ ) {
listHTML += '<li>' + playList[i] + '</li>' ; }
listHTML += '</ol>' ;
print( listHTML ) ;
}
printList( playList) ;
1 Answer
Chris Shaw
26,676 PointsHi Nijad,
What Dave McFarland has taught you in the video is correct as playList
has been passed to printList
as a parameter which means a locally scoped copy of the playList
variable is now usable within printList
thus the code should be referencing list
instead.
function printList(list) {
var listHTML = '<ol>';
for (var i = 0; i < list.length; i++) {
listHTML += '<li>' + list[i] + '</li>';
}
listHTML += '</ol>';
print(listHTML);
}
Happy coding!
Nijad Kifayeh
6,092 PointsNijad Kifayeh
6,092 PointsThanks for clearing that up Chris!!!
Chris Shaw
26,676 PointsChris Shaw
26,676 PointsNo worries.