5. Finding that Special Someone


#1

Syntax Error>>??

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"*/

var search=function(lastName){
var contactsLength=contacts.length;
for(var i=0;i if(contacts[i].lastName===lastName){
printPerson(contacts[i]);
}
}

};
search("Jones");


#2

Hi look at your last function you have more } tha you need

var search=function(lastName){
    var contactsLength=contacts.length;
    for(var i=0;i if(contacts[i].lastName===lastName){
        printPerson(contacts[i]);
    }
}
};<= remove this one

the for loop should have that strcuture

for (statement1, statement2, statement3) {

}

and you already begin with

for (var i = 0;...) {

}

Do you how to on now?


#3

now>?

var search=function(lastName){
var contactsLength=contacts.length;
for(var i=0; i < contactsLength; i++){
if(contacts[i].lastName===lastName){
printPerson(contacts[i]);
}
}


#4

this is correct....

var search=function(lastName){
var contactsLength=contacts.length;
for(var i=0; i < contactsLength; i++){
if(contacts[i].lastName===lastName){
printPerson(contacts[i]);
}
}
};

}; -->> we need this


#5

you stiil have more } than you need..

var search=function(lastName){
    var contactsLength=contacts.length;
    for(var i=0; i < contactsLength; i++){ 
        if(contacts[i].lastName===lastName){
            printPerson(contacts[i]);
        }
    }
};

}; <== remove this