Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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>';
}