27. Loop the loop help


link to the lesson

this appears on the console,

We're running a test below to make sure your code works.
TypeError: Cannot read property 'name' of undefined"


// Our Person constructor
var Person = function(name, 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

I have no idea what is causing this problem!
please help.


Hello @coursepro35324,

change your i <= family.length to i < family.length, because if i makes to family.length, then there won't be an item to iterate over, since array indices are always array.length -1. Hope you understand now...


I cannot find my error. It says: SyntaxError: missing before statement

function Person(name,age){
this.name= name;
this.age = age;
// Our Person constructor

// 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, iconsole.log(family[i].name)


Hello @gigasurfer34739,

Your problem lies in the fact that you haven't written the syntax for your for loop correctly. Just a refresher on the syntax of the for loop...

for(initialization; condition; update) {
    //Some Code!!

So, in order to loop over numbers 1 all the way unto 10, I would use the following...

for(var i = 1; i < 11; i++) {
    //Some Code!

Hope this fixes your problem...


Thank you. So it was just changing coma for semicolon?


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