#27 Loop the loop - tried everything I can think of!


#1


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


ReferenceError: newArray is not defined

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


// Our Person constructor
function Person (name, age) {
    this.name = name;
    this.age = age;
}
// Now we can make an array of people
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);
// loop through our new array
for (i = 0; i < family.length; i++) {
    console.log(family[i].name);
};


#2

The correct way to do it would be new Array();
Hope I Helped :slight_smile:


#3

Oh wow, just needed a space, thanks!!


#5

it proceeds without var, why is that?


#6

I found here some example on declaring variable i in loop.
And for array, for the assignment you can write var family = new Array(); but in practice no one does that because there is simpler and faster solution like:
var family = []; and this gets you new, empty array saved in variable called family.


#7

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