Loop the loop #27


#1

Hi everyone can you help me with this problem? I looked through all the different topics and for some reason mine doesn't work even though it looks like it should? Any help would be appreciated thanks!

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

var family = [];

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

// Now we can make an array of people

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

// loop through our new array


#2

It won't work. Open up Developer tools in your browser and click on the Console tab then you will see that you have a problem. Also I'd suggest you to read more about new Object how it works and what it offers.


#3

Your array needs to be an object. Therefore, you need to change it.

var family = new Array();


#4

I believe your constructor needs to be a function:

function thing(argument1, argument2, etc...){
this.argument1 = argument1;
etc... };
then fix your array as beagot said.
and then, i'm not positive, but i think you have to declare your variables in you for loop.
hope this is correct and helpful


#5

Thank you everyone! I got it now :slight_smile: