JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Build an Object Challenge, Part 2

Jaime Aguilar
Jaime Aguilar
7,237 Points

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

 function print(message){
var question;
var students = [
  { Name:"Jaime",
    Track:"Full-Stack JavaScript",
    Achievements: 12,
    Points: 1404
      Achievements: 50,
      Points: 7414
      Track:"Java Web Developent",
      Achievements: 2,
      Points: 304
      Achievements: 1,
      Points: 50
      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("------------------" + "<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
207,602 Points

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


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; }