Finding that Special Someone


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");

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


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]));


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


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.


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.