Error Message: Make sure you created an Array called family


#1

HELPPPPPPP. please :slightly_smiling:

Code:

// Our Person constructor
function Person (name, age) {
this.name = name;
this.age = age
}

// Now we can make an array of people
var family = new Array();
family[0] = new Person("alice", 40);
family[1] = new Person("bob", 42);
family[2] = new Person("michelle", 8);
family[3] = new Person("timmy", 6);
// loop through our new array
for (var family = 0; family < 4; family++) {
family[0].name;
family[0].age;
family[1].name;
family[1].age;
family[2].name;
family[2].age;
family[3].name;
family[3].age;
}

Error Message:

Make sure you created an Array called family

Instruction:

Write a person constructor called Person that has two properties (name and age).
Create an empty array called family.
There will be four objects in the array. Using your Person constructor, create the four objects and put them in the array. The order of the objects are:

"alice" who is 40
"bob" who is 42
"michelle" who is 8
"timmy" who is 6

Create a for-loop that loops through the family array and prints out the name property for each family member in order of creation.


#6

You successfully created an array called family on this line:

var family = new Array();

then you added several people to it here:

family[0] = new Person("alice", 40);
family[1] = new Person("bob", 42);
family[2] = new Person("michelle", 8);
family[3] = new Person("timmy", 6);

then you wiped them all out and set the family variable to 0 here:

var family = 0;

Do you see the problem with that?

If you understand that, then we can move on to printing out the family members.