Finding that special one


#1

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( n = 0; n < contactsLength); n++){
if (contacts[n].lastName === lastName){
printPerson(contacts[n]);
};
};

};
search("Jones");

Oops, try again. There was a problem with your syntax

I have been checking the codes a number of times and have compared with others codes given in the form, but not able to find anything wrong. Always getting the same remark
"Oops, try again. There was a problem with your syntax"
Can anybody help !! Thank you.

`


#2

I removed the extra bracket ")" provided after n < contactsLength by mistake. But still getting the same error


#3

You need to remove the first closing bracket here:

for( n = 0; n < contactsLength); n++){


#4

I removed the extra bracket, the problem is still not solved. It shows now
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?

can anybody help please. I am really stuck and not able to move forward.
I have done HTML, CSS, and JS so far without any trouble. But really stuck up here. I am exhausted. Please help.


#5

But removing the bracket works for me...
Here's the code:

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( n = 0; n < contactsLength; n++){
if (contacts[n].lastName === lastName){
printPerson(contacts[n]);
};
};

};
search("Jones");

#6

Thank you so much. It is working ok now.