Loop the Loop


#1



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


Oops, try again. Make sure you created an Array called family


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


#2

this:

var family = {};

is not the way to create an array, either use [] or new Array();


#3

oops. I forgot that I'm meant to use []


#4

Problem/issue resolved?


#5

Now I got the error message :
Oops, try again. Make sure to log to the console the name of each object
and the console says:
We're running a test below to make sure your code works.
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 = [];
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(n = 0; n <= length.family; n++) {
    console.log(family[n].name)
}

#6

in the loop itself, i would use < instead of <=, since arrays start counting at zero. and use family.length, you want to get the length of the family, not the family of the length, right?


#7

That worked, but for some reason code academy still put:
We're running a test below to make sure your code works.
with the code:
on the console


#8

please post an updated version of your code


#9

5 posts were split to a new topic: Loop the loop


#10

now it says, oops, try again. Make sure to log to the console the name of each object


#11

Never mind. I got it. Thanks for your help!