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

What up with my code

Just trying this out but it doing nothing is the code wrong somewhere ?

var playlist = ["one", "two", "three"];

function printList(list) {
    var htmlList = "<ol>"
    for(var = i; i < list.length; i+= 1) {
        htmlList += "<li> " + list[i] + " </li>";
    }
    htmlList += "</ol>";
    document.write(htmlList);
}

printList(playlist);

the html is just a standard page linked to this js file

2 Answers

Hi Simon,

Just a few small modifications to your function here:

  • After you've create your htmlList variable make sure you close that line with a semicolon.
  • Starting your for loop var shouldn't equal i it should equal 0 so you start at the beginning of the array you're iterating over.

I hope that helps.

var playlist = ["one", "two", "three"];

function printList(list) {
    var htmlList = "<ol>";
    for(var i = 0; i < list.length; i += 1) {
        htmlList += "<li> " + list[i] + " </li>";
    }
    htmlList += "</ol>";
    document.write(htmlList);
}

printList(playlist);

Yea that's great thanks, so just syntax errors, i have done the most of the fullstack javascript track again forgot most of it .