27 help please


#1


Any ideas as to why this error is happening? I've compared it with other people's code that has been exactly identical and it won't work for me but will for them...


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


This error keeps popping up and I dont know why:
Oops, try again. There was a problem with your syntax.
SyntaxError: Unexpected token [


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


thanks again for any input


#2

is first found here...

We already have declared and defined family as an empty array. Now we just need to load it up.

family[0] = ...

Further about the error, We cannot declare an array element, hence, var family = [] to start off.


#3

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