JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Build an Object Challenge, Part 2 Solution

Brian York
Brian York
6,213 Points

My HTML is off

I got the right output for this challenge, but the spacing in the HTML is off. Can anyone explain to me why this happens? I'm using un-ordered lists because it looks even goofier when I use ordered lists.

Here is the code that grabs the data from the array of objects:

var message = '<ul>';

for (var i = 0; i < students.length; i += 1) { for (var key in students[i]) { message += '<li>' + key + ': ' + students[i][key] + '</li>';
} message += '</ul>'; }

document.write(message);

Thanks for the help, Brian

1 Answer

Not sure what you want your output to look like but I think you want the closing </ul> tag:

message += '</ul>';

outside of your loop. Or your opening <ul> tag inside your loop.

for (var i = 0; i < students.length; i += 1) {
    message += '<ul>';

    for (var key in students[i]) {
        message += '<li>' + key + ': ' + students[i][key] + '</li>';
     } 

    message += '</ul>';
}