5/6 syntax error


#1

This is my code, what is wrong with it?

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

search("Jones");


#2

Ahem, read directions please. Make a search function.


#3

You have a couple of errors actually first

  1. There is a ReferenceError. "lastName" is not defined anywhere. its only defined inside the three objects defined at the top therefore cannot be seen without calling the object
  2. you must remove the last }; before the search("Jones"); call.
  3. You have not implemented any function called search(arguments) but you are calling search("Jones"); as @ragezapper

try to correct these and it will work


#5

thank for listing the errors now I know what to fix.