"undefined"?


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

/*Create a search function
then call it passing "Jones"*/
function search(lastName) {
var contactsLength = contacts.lastName;
for (var j = 0; j < contactsLength; j++) {
if (lastName = lastName) {
printPerson(contacts[j]);
}
}
};
when i call the list function it says i passed, but the instructions told me to call the search function. but when i do it says its "undefined".
list();


#2

your search function should be this

/*Create a search function
then call it passing "Jones"*/
function search(lastName) {
    var contactsLength = contacts.length;
    for (var j = 0; j < contactsLength; j++) {
        if (contacts[j].lastName == lastName) {
             printPerson(contacts[j]); 
        }
    }
}

search("Jones");