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

Ahmed Hassan
Ahmed Hassan
5,533 Points

Why too much code?

//Why too much code while I can just do this and give the same results:

var PlayList=[
"Love Song", 
"Crazy about you", 
"Lithium", 
"Pretty"
];

document.write("<h1>My Play List</h1>");
document.write("<ol>");
for (var i=0; i<PlayList.length; i++) {
    document.write("<li>"+PlayList[i]+"</li>");
}
document.write("</ol>");

/* Result:
My Play List

1- Love Song
2- Crazy about you
3- Lithium
4- Pretty
*/

1 Answer

Writing a bit more code can make your JS program more dynamic so you don't need to edit more, even though writing less seems best at the start, sometimes writing a little bit more can be very convenient.