Search function not working


#1

please help
can u advice me on where do i have a syntax error?
and why the search function is not returning "Bob Jones"?

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

search("Jones");


#2

should read,

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

#3

@mtf, one of these days I'm going to press reply before you... one of these days.


#4

You'd be surprised how often you actually do. I'm only ever in and out and peruse a few threads at a time, some new, some already underway. Some toe-stepping is to be expected, one supposes...


#5

yes ur right
that line got the prob

and not only the quotes

also im missing a dot there after array name and before its property
if (contacts[i]lastName === "lastName")
should be
if (contacts[i].lastName === "lastName")

thank u very much for ur help