27. Loop the Loop SYNTAX ERROR


#1

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

I've looked this up and down and I cant figure out where the sytax error is.


#2

In your Person constructor, remove the = so that it reads as: function Person (name,age) {


#4

Those don't help, the problem is referencing the array.


#5

Try this

function Person(name,age){
this.name = name;
this.age = age;
}
var family, success;
family = [];
var addToArray = function(arrayName){
var len;
if (arguments.length > 1){
len = arguments.length%2 ? arguments.length : arguments.length+1;
for (var i = 2; i arrayName.push(new Person(arguments[i-1], (arguments[i]||0)));
}
return true;
} else {
return false;
}
};


#6

two minor things: 1) you didn't declare i as a variable
2) you should be trying to print the name, not the age


#8

here is the correct 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 < family.length; i++){
console.log(family[i].name);

}