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

My solution. Thoughts?

var students = [
  {
    Name : 'Taylor',
    Track : 'Front End Development',
    Achievements : '100',
    Points : '1000'
  },
  {
    Name : 'Todd',
    Track : 'Diesel Mechanic',
    Achievements : '45',
    Points : '103'
  },
  {
    Name : 'Jordan',
    Track : 'Loser',
    Achievements : '76',
    Points : '344'
  },
  {
    Name : 'Ryne',
    Track : 'Winner',
    Achievements : '4',
    Points : '54'
  },
  {
    Name : 'Nick',
    Track : 'Baller',
    Achievements : '43',
    Points : '5'
  }
];
var html = '';

function print(message) {
  document.write(message)
}

// Cycling through each object to print html
for (var i = 0; i < students.length; i++) {

  // Printing prop and values. Name prop is header
  for (var prop in students[i]) {
    if (prop === 'Name') {
      html += '<h2>' + prop + ': ' + students[i][prop] + '</h2>';
    } else {
      html += '<p>' + prop + ': ' + students[i][prop] + '</p>';
    }
  } // end for in

}

print(html);

Thanks a bunch!

1 Answer

:+1: Looks great