What is wrong? (Intro to objects 27/33)


#1

**It says I don't have an array called family. **

// 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 (i = 0; i < family.length; family++){
console.log(family[i].name);
}


#2

Hi @maxb55555

You have to change your "for" loop : (i++ not family++)

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

Hold on :wink:


#3

@maxb55555 you should use brackets with an array, not parentheses:

var family = new Array();

#4

No, both ways work:

var family = new Array(); //works

var family[] = new Array {//code goes in here}

#5

@freginold you have differents way to create an array, but they do exactly the same.

var family = new array();    //constructor method
var family = [];    //linear method

For simplicity we use the first one, but you can use what you want :smile:


#6

@ragezapper and @onepunch_man thanks for pointing that out, didn't know you could do it either way. happy to learn something new.


#7

your counter increment is incorrect, it should be i++ not family++