27. Loop The Loop error message. Help Please?


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

https://www.codecademy.com/courses/spencer-sandbox/4/2?curriculum_id=506324b3a7dffd00020bf661#
<In what way does your code behave incorrectly? Include ALL error messages.>
here is my code:

// 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 am getting an error message with red triangle:

Oops, try again. It looks like you have an error in your code. Here’s the message: TypeError: Cannot read property ‘name’ of undefined

then I get this error in the console window:

We’re running a test below to make sure your code works.
alicebobmichelletimmy
TypeError: Cannot read property ‘name’ of undefined

I’m sure this is something simple, I’m just not seeing it. Thank you for any and all help!



Replace this line with your code. 


indent preformatted text by 4 spaces


#2

When i reaches family.length it is out of range.

 i < family.length; 

#3

Thank you, that worked. I appreciate the help.


#4

A post was split to a new topic: (family[i].name)" is not defined