4. Listing Everybody


#1

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

Hi guys!

I pass the exercise but both names are printed twice whereas I think the aim of the exercise was to get each of them printed only once. Can anyone explain what I am doing wrong?

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 ();


#2

Once for your test line, and once for the lesson checker's test. Ignore the extra output.


#3

Thanks a lot for the explanation!


#4

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