27. I'm getting it to print properly, but I'm getting an error


#1


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


I'm getting the array to print the names properly, but for some reason I'm still getting this error:

"Oops, try again. When trying to create a new Person the following error was thrown: TypeError: Person is not a constructor"

I'm pretty sure I set it up as a constructor correctly, but not sure what the error means, or how to fix it.


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

// Now we can make an array of people
var family = 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 (Person in family) {
    console.log(family[Person].name);
};


#2

Person is the name of the class. We would not wish to overwrite this by making it a trivial variable. Use lowercase so you do not obliterate the class definition else all the instances vanish into thin air.


#3

Interesting, yet the code will still work properly?


#4

for (i=0;i<family.length;i++){
console.log(family[i].name);
};

try this to use for loop


#5
var family = new Array();

#6

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