27 Loop the loop


#1

Hi folks!

Having a bit of trouble here trying to figure out what's giving me an issue. Getting a "It looks like the object at index 0 was not created with the Person constructor"...Can't seem to figure it out and was looking for some help!

// 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] = Person("alice", 40);
family[1] = Person("bob", 42);
family[2] = Person("michelle", 8);
family[3] = Person("timmy", 6);

// loop through our new array
for(i = 0; i < family.length; i++) {
console.log(family[i].name);
}

Thanks!


#2

For each of the four, write, ... = new Person( ... );.


#3

gah...stupid...thank you!


#6

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

var family = new Array()
var family[0] = new Person("alice", 40)
var family[1] = new Person("bob", 42)
var family[2] = new Person("michelle", 8)
var family[3] = new Person("timmy", 6)

for(var i=0; i console.log(family[i].name)
}

CAN SOMEONE TELL ME WHAT'S WRONG WITH MY CODE pls!


#7

Some code missing here.

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