Listing Everybody


#1

Hi, i got the code right but it keeps printing out the names twice. What am i doing ?

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

list();


#2

first of all remove 1 from "for" loop
try to remove "list" and u will see that only two names are now printing
this is because of "printPerson(contacts[i]);"
actually as instruction says(The list function loop through every member of the contacts array and print its information)
so the list() is printing your other 2 values
correct me if i am wrong
#beginner