Why is the o/p printing twice in the console? Kindly explain


#1



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


o/p : : Bob Jones
Mary Johnson
Bob Jones
Mary Johnson


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 (var i = 0; i < contactsLength; i++) {
        printPerson(contacts[i]);
    }
};
list();


#2

I believe it may just be a glitch in codecademy because if you paste that code into another page it only prints once.


#3

ok ...thanks a lot :slight_smile: