Loop the loop has a problem


#1


https://www.codecademy.com/courses/spencer-sandbox/4/2?curriculum_id=506324b3a7dffd00020bf661#


SyntaxError: Unexpected token =


`

// Our Person constructor
function= Person(name,age){
this.name=name;
this.age=age;
};
// Now we can make an array of people
family=[];
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);
};


#2

Your problem is here,

You are supposed to be creating a new array,

var family = new Array();

Not an empty list.


#3

I changed it but still the same error
If it was the problem why did i passed the previous step with the same code? (Arrays of Objects)


#4

The issue is here (in your first line): "function= Person(name,age)"! You need to remove "=" here!

And in the 7 line you need to add after "=" new Array();

Here is corrected 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);
};


#5

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