Introduction to Objects 1 - Q27 (Please Help me ! )


#1

The following is my codes and I find them all correct. Can anyone help me ?

// 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

Please Help me !!!

I need your help ^_^

Thanks !!! :slight_smile:


#3

Haha.... This is exactly where I am now.... Surprised to find out someone is stuck at the same place and time as me. *waiting for answer***


#4

HaHa

I find my codes all correct and no idea what the problem is?

By the way, where are you from ? I am un undergraduate from HK.


#5

Please, remove the key var when you declare the values to family[x]

I put this, and works correctly

// 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].name);
}


#6

I'm a graduate, from Nigeria


#7

Thank you !!!

I am stupid. When I look at the Q26, the answer is shown already. Thank you !!!


#8

I keep going ^^ :slightsmile:


#9

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