Finding that Special Someone


#1

Hi everybody,
I am not sure what I am doing wrong here. And I am a little bit fried.
The error message is:
Oops, try again. It looks like your search function didn't log "Bob Jones" to the console. Did you remember to call search after you defined it?

Thanks in advance for your help.
:sleeping:

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.length;
	for (var i = 0; i < contactsLength; i++){
        if(contacts[i].lastName === lastName) {
        	printPerson(contacts[i]);
        } else {
            return "There is no such a person in the list";
        }
    }
}

search("Bob Jones");


#2

when you call the function, you should only provide the surname as argument, given your function compares with the last name from the objects:

if(contacts[i].lastName === lastName)

#3

Good morning all.

It seems that I have found what was wrong from previous posts.