27/13 in JS: loop the loop. plz help me!


#1



someone please help me, I have tried everything i can think of
(refreshing, editing, re-editing, etc.) I even looked at other peoples problems!!!!!
(still did not work...) no matter what i do i still get an error of some sort...
(depends on code) this is my latest version,
can someone tell me what in the world is going on?


var Person = function(name, age){
    this.name = name;
    this.age = age;
};

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

for(var i = 0; i <= family.length; i++){
    console.log(family[i].name);
};
...i - i just - feel so hopeless...


#2

What's the error for this version?


#3

remove the = sign

i <= family.length // from here


#4

it keeps saying that 'name' is undefined... why?


#5

Have you changed the code at all? If so please post the new code that you have.


#6

no i havent changed the code just yet... it's still the same as my first post.


#7

Make sure that you remove the =, like @rcodeman said, here:

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

#8

finally!!!!!! thank you so much!!! who knew that was the problem this whole time? but still thank you so much you guys!


#9

it works!!!!!!!!!!!

var Person = function(name, age){
this.name = name;
this.age = age;
};

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

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

console.log(family[i].name);
};