#27 What is wrong with my code?


#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();
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);
}


#2

var family = new Array;

that is it!


#3

var family = new Array(); //is cool
But Children of Array are not defined by 'VAR' keyword..
As "VAR" - makes a different type..(not a child of Array)
- Remove "VAR" from Children and Your code will be fine.


#4

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

// Now we can make an array of people
var familiy = 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 < family.length; i ++) {
console.log("Our family contains " + family[i].name);
}


#5

@abdullah_alhasan I have same code like you, but it is not working.

Then i copy your code, and everything is correct o.O

I dont understand....Im so confused :smiley:


#6

you spelled family wrong when making the array

you wrote "var familiy"


#7

abdullah whatever thanks it helped a lot