27.Loop the Loop (Syntax error?)


#1



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


There is a problem with your syntax.

I can't figure out what is wrong with my code.


// Our Person constructor
var Person = new Object(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);
};


#2

HI first here

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

instead of new Object put function like that

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

then the for loop you should remove the = to <= because the family.length is equal to 4 but the array starts counting from index 0 so it's ..

0, 1, 2, 3, 4

which make 5 number but the family array only got 4 name.


#3

That did the trick. Thanks Wizmarco!