27. Loop the Loop


#1


https://www.codecademy.com/courses/spencer-sandbox/4/2?curriculum_id=506324b3a7dffd00020bf661#


I'm getting the error message It looks like the object at index 0 was not created with the Person constructor, but I can't figure out why. I've checked other posts in the Q&A forum and my answer looks similar...


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

// Now we can make an array of people
var family = new Array();
    family[0] = Person("alice", 40);
    family[1] = Person("bob", 42);
    family[2] = Person("michelle", 8);
    family[3] = Person("timmy", 6);

// loop through our new array
for(var i = 0; i<4; i++) {
    console.log(family[i]);
};


#2

if you want to create an instance of your object you have to use the new keyword:

family[0] = new Person("alice", 40);

#3

Excellent! Thank you!


#4