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 1

Bei Mi Chen
seal-mask
.a{fill-rule:evenodd;}techdegree
Bei Mi Chen
Full Stack JavaScript Techdegree Student 6,720 Points

Not sure what kind of record the task is asking for but here it is. Any way I can improve this?

var students = [ 

  { 
  name: 'Ben',           //Name with string value
  track: 'Javascript Full Stack',          //eg. iOS, Web Design, Front End Development, Etc.
  achievements: 6,   // Should hold a number value.
  points: 3005,         //holds number of points student has earned
  }, 

 { 
  name: 'Danny',        
  track: 'Python for Data Analysis',          
  achievements: '3',   
  points: 118,                 
  },

  { 
  name: 'Hasanda',          
  track: 'Frontend Development',          
  achievements: 30,   
  points: 30000,                
  }, 

  { 
  name: 'Tony',           
  track: 'Backend Development',          
  achievements: 40,  
  points: 40000,                    
  }, 

  { 
  name: 'Luke',           
  track: 'Java Backend Development',          
  achievements: 40,   
  points: 40000,                      
  } 

];

function print(message) {
  var div = document.getElementById("output");
  div.innerHTML = message;
}

function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}

var studentList = "<h1>Here is a list of students: </h1> <ol>";

for(i = 0; i < students.length; i += 1) {
  studentList += "<li>";
for (var key in students[i]) {
  studentList += capitalizeFirstLetter(key) + ": " + students[i][key] + "<br>";
  }                  
  studentList += "</li>";
}  

studentList += "</ol>"+ "<br>";

print(studentList);

1 Answer

Steven Parker
Steven Parker
231,236 Points

It looks like you already improved it, two different ways.