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

My solution to Part 2

var students = [
  {
    name: 'Elena Torrey', 
    track: 'Front End Web Development', 
    achievments: 1005, 
    points: 3456
  },
  {
    name: 'Lionel Messi', 
    track:'iOS', 
    achievments: 507, 
    points: 3872
  },
  {
    name: 'Cristiano Ronaldo', 
    track: 'Web Design', 
    achievments: 297, 
    points: 9084
  },
  {
    name: 'David Beckham', 
    track: 'Python', 
    achievments: 803, 
    points: 6209
  },
  {
    name: 'Neymar', 
    track: 'JavaScript', 
    achievments: 452, 
    points: 6197
  }
];

var html = '';

for (var i=0; i<students.length; i+=1) {
  student = students[i];
  html += '<h2>Student: ' + student.name +'</h2>';
  html += '<p>Track: ' + student.track +'</p>';
  html += '<p>Achievment: ' + student.achievments +'</p>';
  html += '<p>Points: ' + student.points +'</p>';
};

function print(html) {
  document.write(html);
}


print(html);
Adrian Thomas
Adrian Thomas
1,572 Points

It's cool that you assigned the variable students to students[i]. That way you really can just access the property using just student

This alternative would work in the long run when you have a lot of properties and values in an object and could just make a change to that variable instead of tracking every single [i] in the object and changing it.

Good idea!