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

Any reason not to use this function?

I got a working version of the function using the following method. Any reason something like this wouldn't be advised? It seems cleaner to me to have this as student_report.js

for (var i=0; i<students.length; i+=1) {
  document.write('<h2>The Student: ' + students[i].name + '</h2>');
  for( var key in students[i]) {
   if(key != 'name') {
     document.write('<p>', key, ': ', students[i][key], '</p>');
   }
  }
}

1 Answer

Steven Parker
Steven Parker
231,275 Points

I can think of three potentially significant differences from the video solution:

  • you don't have control over the property display order with this method
  • you don't have the opportunity to show alternate key names (or capitalizations)
  • a missing property won't be shown at all (instead of shown as "undefined")

The importance of these differences might vary with the specific project and data set.