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

Anthony gedeon
Anthony gedeon
6,140 Points

I keep on getting undefined

let student;

for(let i = 0; i < students.length; i++){
  student = students[i];
  for(let prop in students){
    if(prop === 'name'){
      document.write('<h2> student: ' + student[prop] + '</h2>');
    }else{
       document.write('<p>' + student[prop] + '</p>');
    }
  }
}

1 Answer

Steven Parker
Steven Parker
177,844 Points

In your inner loop:

  for (let prop in students) {

You have "students" (plural) but I think you meant to write "student" (singular) there.