27. Loop the Loop, Create array Family


#1


I have the code below and it is working. It prints out the names, no problem BUT I still get an error message that says "Oops, try again. Make sure you created an Array called family"

I have an array on line 6 called family... so I am lost as to what is wrong....


// Our Person constructor
Person = function(name, age){
    this.name = name;
    this.age = age;
}
var family = {};
// Now we can make an array of people
family[0] = new Person("alice", 40);
family[1] = new Person("bob", 42);
family[2] = new Person("michelle", 8);
family[3] = new Person("timmy", 60);

// loop through our new array
for( var key in family){
    console.log(family[key].name);
}


#2

Please post always the link to the lesson

Create a new Array

var family = [];
// or
var family = new Array();

And here is a typo

family[3] = new Person("timmy", 60); // 6 not 60

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.