Loop the loop nothing gets printed


#1

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

I have no idea why nothing gets printed. I pass the exercise but nothing gets printed. Tried on different platforms

Replace this line with your code. 
// Our Person constructor
function Person (name, age)  {
    this.name = name;
    this.age = age;
}

// Now we can make an array of people
var family = [];
var alice = new Person("alice", 40);
var bob = new Person("bob", 42);
var michelle = new Person("michelle", 8);
var timmy = new Person("timmy", 6);
// loop through our new array

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


#2

You have to put all the variables(Objects) inside the family Array.
variables - alice,bob,michelle,timmy.

As youre looping over an empty array so its prints nothing.


#3

Oh well :smiley: It's bit embarrassing.


#4

It happens ,use a technique called Rubber duck debugging for hunting bugs!
cheers! :thumbsup:


#5

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