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
177,538 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; }