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

How to get the first line of each object in bold?

 function print(message){
  document.write(message);
}
var question;
var students = [
  { Name:"Jaime",
    Track:"Full-Stack JavaScript",
    Achievements: 12,
    Points: 1404
},
  {
    Name:"Chelsea",
      Track:"IOS",
      Achievements: 50,
      Points: 7414
  },
  {
    Name:"Francine",
      Track:"Java Web Developent",
      Achievements: 2,
      Points: 304
  },
  {
    Name:"Sally",
      Track:"Ruby",
      Achievements: 1,
      Points: 50
  },
  {
    Name:"Brooke",
      Track:"Full-Stack JavaScript",
      Achievements: 78,
      Points: 15081
  }
];
//for loop cycles though all items in the array
// for in loop cycles though all objects
//key represents each object {} name (ex) name:, track:
// students[i][key] prints out everything in that object: ex things in quotes
for(var i = 0; i<students.length; i+=1){
  for(var key in students[i]){
    print("<li><B>" + key + ": " +"</B>" + students[i][key] +  "</li>"+"");
  }
  print("</ul>");
  print("------------------" + "<br>")
}

This is what i have so far, not sure how else to style it to show where one object ends and the other begins.

1 Answer

Steven Parker
Steven Parker
229,670 Points

First, it looks like you're missing the opening tags for your lists. The first line of the outer loop should probably be:

  print("<ul>");

Then, since you're inner loop works by key, you'd need some extra code to determine which one is first. Perhaps a boolean that is set in the outer loop and cleared once the first item has been printed?

But it's also something that can easily be done just with CSS:

li:first-child { font-weight: bold; }