Loop the Loop


#1


https://www.codecademy.com/en/courses/spencer-sandbox/4/2?curriculum_id=506324b3a7dffd00020bf661#

It keeps printing alice, but won't print anyone else? What's wrong with the code?


// 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 (var i = 0; i < Person.name; i++); {
    console.log(family[i].name); 
};


#2

@melimelicxo This is what is wrong:

change this:

to this:

family.length

then change this:

to this:

console.log(family);

Hope this helps

Steven


#3

for (var i = 0; i < Person.name; i++); { // here remove ;
console.log(family[i].name);
};

and what is the value of Person.name ????
so write family.length instead of Person.name


#5

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