27. Loop the Loop - Syntax error


So I'm trying do run the code below:

// 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 <= family.length, i++){

But it keeps saying "SyntaxError: Unexpected token )", and I can't see what's wrong...
Can someone help me please?


Never mind, just realized I wasn't isung a semicolon on

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


The last index of a list will be 1 less than the length, so don't include the actual length in the loop. The conditional ends with a semi-colon, not a comma.

i < family.length;


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