27 invalid left hand side in assignment


#1

function Person(name, age){
this.name = name;
this.age = age;
};

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

for ( var i = 0; i < 4 ; i++)
{
console.log(family[i].name) ;
}

out out says invalide left hand side in arugment, but if i copy the code from previous section which is identical except the for loop it works


#2

your code should look like this

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

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


#3

Thank you this helped me out! However in this problem they ask us to print just the name of each member, so we need to log on line 16
console.log(family[i].name);


#5

For the record, the above is what is throwing the error. We write it either like this,

var family = new Array();  // Array constructor

or

var family = [];           // Array literal

The new operator is only used in conjunction a constructor function.


#6

omg, thank you so much, i was banging my head against the wall, i should have caught that thank you