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



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) {


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.


Interesting, yet the code will still work properly?


for (i=0;i<family.length;i++){

try this to use for loop

var family = new Array();


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