Output printed twice


#1


URL : https://www.codecademy.com/en/courses/building-an-address-book/0/4?curriculum_id=506324b3a7dffd00020bf661


This is the code I have:

var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"
};

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "mary.johnson@example.com"
};

var contacts = [bob, mary];

function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);
}
var list = function () {
    //var contactsLength = contacts.length;
    for (i = 0; i < (contacts.length); i++) {
            printPerson(contacts[i]);
    }
};
list();


The output for this code is:

Bob Jones
Mary Johnson
Bob Jones
Mary Johnson

Can you please help me understand why the code looped twice?


#2

@sureshdev,
In some sections of this course, the course-checker Display's data
this you could then identify by placing two EXTRA code-line's:
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );

Thus use

list();
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );