Finding that Special Someone


#1

Here's my code:

/*Create a search function
then call it passing "Jones"*/

var search = function (lastName) {
var contactsLength = contacts.length;
for (var i = 0; i < contacts.length; i++) {
if ( lastName == contacts[i].lastName) {
printPerson } else {
console.log("Couldn't find any result");
}
}
}
search("Jones");

It doesn't show any result. Where am I making the error?


#2

You are making the error on printPerson. You are just writing printPerson without definding what should be printed. You can chnage it too: console.log(printPerson(contacts[i]));

ALL THE CODE:

var search = function(lastName){
    var contactsLength = contacts.length;
    for(var i = 0; i < contactsLength; i++){
            
            if(contacts[i].lastName === lastName){
                console.log(printPerson(contacts[i]));
                }else{
                console.log("We could not find any name")    
                }
        }
    };
search("Jones");

#3

Thank you, I didn't understand that very well. Now I understand that I wasn't giving the parameter to the function.

Thanks a lot.


#4

The only issue with your "else" portion of your statement is that now every time it comes across a name that doesn't have the last name "Jones" it will print out "We could not find any name" even though it actually can.


#5