Loop the loop


#1


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


"Oops, try again. It looks like the object at index 0 was not created with the Person constructor"

Checked the forums several times on this excercise/issue, still unable to see what the issue is. Have tried changing i < family.length to i <4 as suggested on most of the forum answers, still not working. Help would be greatly appreciated!


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


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


#2

var family = newArray();

you want to create a new Array() which requires a space between the words (so you have new keyword and array object)


#3

for (var i = 0; i < 4; i++) instead of 4, type family.length


#4

oh just saw you tried it


#5

:open_mouth: I new it'd be something as simple as a space! Thanks so much, that was driving me crazy!


#6

no problem, i would then go back to family.length (like @finjii suggest), this way, your code can easily handle more or less Person members


#7

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