Building an Address Book issue


The code works but it console.logs out undefined as well. When i had the (var i =0; i<contactsLength; i++) as (var i =0; i<contactsLength -1; i++) it wouldn't work but once I took out the -1 it worked. I want to make sure I understand whats the issue not just complete the challenges. Can anyone help me?

var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: ""

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: ""

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++){



The function already logs, but has no return value. Since you are logging again, you are logging undefined.

console.log(console.log());    // undefined


I changed console.log(printPerson(contacts[i])) to return (printPerson(contacts[i])) but it won't log mary johnsons name


There is no need to return. Just don't log the function call expression.

    for (var i = 0; i < contactsLength; i++) {


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