4. Listing Everybody (undefined error)


#1



4. Listing Everybody

While the code I wrote passes, there is a problem with it in that there is a line in the printout that states "undefined." I'm not sure why I'm getting this error.


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++) {
    console.log(printPerson(contacts[i]));   
  }
};

list();


#2

console.log(printPerson(contacts[i]));

this is causing error


#3

take out the console.log();


#4

Thank you both. I would never have thought to take that piece of code out.


#5

I've 'passed' this portion of the lesson but...

Can anyone please explain why "undefined" is being printed in the console between Bob and Mary's names?

Seems odd, and I just want to understand what is being processed here.
Thanks in advance for any help understanding!

Alex