Strange error for Loop the loop


#1



Loop the loop

Hi, for some reason, every time I try to run my code, it gives me the error message below. I've tried resetting the code, and yet it still does it. It looks correct to me, but obviously, could be wrong

error:
We're running a test below to make sure your code works.

TypeError: Cannot read property 'name' of undefined


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


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


#2

Should be < alone or =<


#3

@treeno, this line:

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

you should create new person (new instance):

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

which means you need the new keyword. Same for all the others


#5

That's great thanks!