Object I: Looped the loop


#1


Hi all, I managed to print all the names in the correct order to the console. However, I got the error message "Oops, try again. Looks like your Person constructor does not properly save the second argument as age." but can't seem to figure out why! Would love the help! Thank you :slight_smile:


Replace this line with your code. 
// Our Person constructor
function Person(name, age){
    return this.name = name;
    return 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 x = 0; x<family.length; x++){
    console.log(family[x].name);
}


#2

Only specially written constructors have a return. The normal usage of a constructor function it to generate new instances of the class. Remove the return in both lines.


#3

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