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

Ronald Opara
seal-mask
.a{fill-rule:evenodd;}techdegree
Ronald Opara
Full Stack JavaScript Techdegree Student 3,201 Points

Tips on my code??

var students = [
  { 
   name: 'Chris', 
   track: 'FullStack Javascript',
   achievements: 46,
   points: 566,
   age: 23
  },
  {
   name: 'Rachel', 
   track: 'Java',
   achievements: 62,
   points: 776,
   age: 25
  },
  {
   name: 'Nick', 
   track: 'Python',
   achievements: 55,
   points: 590,
   age: 23
  },
  {name: 'Katie', 
   track: 'Front End Developement',
   achievements: 76,
   points: 1001,
   age: 22
  },
  {
   name: 'Joey', 
   track: 'SQL',
   achievements: 77,
   points: 1055,
   age: 26
  }
];


for ( var prop in students ) {
//  console.log( students[prop].points );
  var message = '<h1>Students: ' +  students[prop].name + '</h1>'
  message += '<p>Age: ' + students[prop].age + '</p>'
  message += '<p>Track: ' + students[prop].track + '</p>'
  message += '<p>Points: ' + students[prop].points + '</p>'
  message += '<p>Achievements: ' + students[prop].achievements + '</p>'
 document.write(message);
}

It was tough to solve at first, because I had trouble figuring out how to access my values. Took about an hour and half to solve, but if someone can please critique my code that would be great.

1 Answer

You've done a great job Ronald. I like your variable name and the explicit nature of your code. However, to improve on this, you should always remember to remove unused code like the commented out console.log. You can also read up on using const and let as the var keyword has global scope.