This forum is now read-only. Please use our new forums at discuss.codecademy.com.

396 points
Picture
Submitted by
Bader Tariq
almost 4 years ago

Helppp;

function Person (name, age) {
this.name = name;
this.age = age;
}
var family= new Array();

for(var i=0;i <= 4;i++){
family[i]=new Person(prompt(),prompt());
};


0 votes

permalink

What are you trying to do? Array is not an Object so you do not create it like new Array().
just do:

var family = [];

and at the end of your for loop you do not need ";"

1267 points
55e8c64f86f552bdc700002e_885571055
Submitted by
Bekzot Azimov
almost 4 years ago


0 votes

permalink

Try this:

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

265 points
Df6af3fa455d709a73b226f9191872a9?s=140&d=retro
Submitted by
GabrielMttr
almost 4 years ago


0 votes

permalink

I coded like this. It works.

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

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

760 points
513cc8dcb41f42e94d000baa_231594658
Submitted by
Tuesday Peacock
almost 4 years ago