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

1 Answer

Victor Mercier
MOD
Victor Mercier
Treehouse Moderator 11,668 Points

Hi Richard, you are getting an undefined because you are calling the name property, the track property on array of object instead of calling it on the studentinfo variable, which is keeping track of the current student. By doind this, you should be able to call the property and you shouldn't get undefined anymore.

So, here is the code:

for (var i = 0; i < students.length; i += 1) {
  studentinfo = students[i];
  message = "<h2>Student : " + studentinfo.name + "</h2>.";
  message += "<p>Track : " + studentinfo.track + "</p>.";
  message += "<p>Points : " + studentinfo.points + "</p>.";
  message += "<p>Achievements : " + studentinfo.achievements + "</p>.";
  print(message);
}

Do not forget to mark as best answer if it helped you!