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 1

Mohamed Ahmed
Mohamed Ahmed
7,449 Points

I did it , That's my code

That's my code for this challenge

// 1- Array to hold Students Objects
var students = [
    {
        name: "Mohamed Ahmed Hassanin",
        track: "Front End Development",
        achievements: 17,
        points: 850,
    },
      {
        name: "Michel Jordon",
        track: "iOS Development",
        achievements: 12,
        points: 712
    },
      {
        name: "Jhon Stewart",
        track: "Android Development",
        achievements: 14,
        points: 650
    },
      {
        name: "Danial Noh",
        track: "PHP Development",
        achievements: 17,
        points: 800
    },
      {
        name: "Izak Benjammen",
        track: "Ruby Development",
        achievements: 7,
        points: 600
    },
      {
        name: "James Braker",
        track: "Design",
        achievements: 15,
        points: 812
    },
]

// 2- This Function to Convert any string from lowerCase to TitleCase
function toTitleCase(str)
  {
    return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() +         txt.substr(1).toLowerCase();});
}

// 3- For loop to generate each student objects data and print it to a web page
for (var i = 0 ; i < students.length ; i++){
    for (stprop in students[i] ){
        document.write('<p>'+'<span style="font-weight: bold">'+toTitleCase(stprop)+'</span>'+': '+students[i]   [stprop]+'</p>')
    }
    document.write('<br>');

}

I don't think you need a comma after the last object.

1 Answer

john Soto
seal-mask
.a{fill-rule:evenodd;}techdegree
john Soto
Full Stack JavaScript Techdegree Student 4,697 Points

var student = [

{name: 'John', track: ' IOS', achivements: 349, points: 45635},
{name: 'Gaby', track: 'Android', achivements: 449, points: 12345},
{name: 'Mackayla', track: 'ruby', achivements: 149, points: 124565},
{name: 'Olga', track: 'python', achivements: 649, points: 2235},
{name: 'Karen', track: 'json', achivements: 749, points: 12435}

];

var html ;

function jsUcfirst(string) { return string.charAt(0).toUpperCase() + string.slice(1); }

for (var i = 0; i < student.length; i++) { for(var key in student[i]) { html = document.write('<p>' + jsUcfirst(key), ' : ', student[i][key] + '</p>'); } document.write('<br>'); }