27.Loop the loop


#1


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


Oops, try again. It looks like the object at index 0 was not created with the Person constructor


// 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 i = 0; i<family.length; i++) {
    console.log(family[i].name);
}

I cant seem to find the problem with my code and i dont understand the error message. Anyone that can help me out? Thank you in advance.


#2

var family = new array();

When we define an Array using Array object we use

new Array() not new array() (Capitalized A)

Can you catch the difference?
Also its not considered to be a good practice.

use [] instead of that!


#3

Found my typo, thx for spotting it!

Got curious and tried to use an array literal notation instead. It works, but the lesson sadly insists that you use "bad practice?" to solve the lesson, in the form of a object constructor.

But thanks for the tip anyway.


#4

#5

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