27. Loop the loop glitching console


#1

I pass on 27. Loop the loop but prints out weird stuff to the console. Below is a link to the exercise, my code, and the console.

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

alice
bob
michelle
timmy


We're running a test below to make sure your code works.
alicebobmichelletimmy

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

#2

Wait what's your question exactly?


#3

Why does this
alice
bob
michelle
timmy
---
We're running a test below to make sure your code works.
alicebobmichelletimmy
appear in the console after running the code?


#4

oh okay, the part below --- is CodeAcademy testing your code.

For the top half, lets look at your code. This

is creating an array, or a list, of new objects, in this case each "Person".

This part:

runs through the array you just created and prints out the objects names, which is why you see the top half of what's printed on the console. Hope this explains it a little :slight_smile: