27/33 Loop the loop


#1

Hi all, I have got some issues with this exercise. Here is my code:

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

The error I get is: The following error was thrown when trying to test the family array: TypeError: invalid 'instanceof' operand Array.

Does anyone know what I have to adjust to the code?

Thanks in advance!


#2

Try to change condition:

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

#3

I restarted my computer and now it worked! I think it was a test error or something. Thanks anyway! :smiley:


#4

It's good, but if you have an array you should to use length property. :slight_smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.