Cannot find error in lesson 27


#1

At this point .. I have no idea what is wrong ..
The console just keeps telling me I am missing a ";" somewhere... lol

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

// Now we can make an array of people
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);

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

27 Loop The Loop
#2

re-evaluate your condition here.

get rid of this semicolon


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

Like this?
keeps giving me the same error.


#4

this is the part i want you to check carefully and logically


#5

still couldn't figure it out :frowning:


#6

Oh I got it, apparently I didn't have to use var to redefine a new person array segment.
So when I removed the var after i declared the Array(); for every family member it worked.


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

#7

One additional improvement is to declare the "i" variable as part of the for statement, to save a line of code, like this:

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