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 Data Using Objects The Build an Object Challenge, Part 2 Solution

Alexander Toropov
Alexander Toropov
6,738 Points

My solution is quiet different. Could you point something in my code, as if I'm moving in to the right direction or not.

function buildHTML (arr) {
    var html = ' ';

    for (var i = 0; i < arr.length; i += 1) {
        html += '<p> Student ' + (i + 1) + '</p>';
        html += buildListFromObject(arr[i]);    
    }
    return html;
}

function toUpper (str) {
    return str.charAt(0).toUpperCase() + str.slice(1);
}


function buildListFromObject (obj) {
    var html = '<ol>';

    for (var prop in obj) {
        html += '<li>' + toUpper(prop) + ': ' + obj[prop] + '</li>';
    }

    html += '</ol>';
    return html;
}

print(buildHTML(students));

Oh, and the reason for different headings, I've done the task right after part one video.

1 Answer

Kevin Gates
Kevin Gates
15,052 Points

If the solution is different than what he/she expects you to put, it may mark it as wrong. These automated quizzes are sometimes looking for a particular result, and you need to use the process they recently instructed you on.