Listing everybody


#1

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

list();

Well my code is correct but i dont understand why bob jones and maryjohnson is coming 4 times! instead of coming 2 times in the list!


#2

because the exercise also calls the list() function for validation purpose.


#3

You are correct, thank you:slight_smile:.


#4

@gourav_roy:

As exercise also calls the list() function for validation purpose, it prints twice. So no need to worry, please proceed with further exercise. Thanks.


#5

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