[Solved] Finding that Special Someone



I got it to print out the last names, but the error occurred when I tried to see if the param equaled the last name.


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++) {

/*Create a search function
then call it passing "Jones"*/

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


Here you have a problem, because you put object, but function expect string value:


Note: you need to put last name.


Thanks. I had to modify the code so it came out as the first and last name, but thanks for pointing out the mistake


For this goal you can use function printPerson:

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

Don't Repeat Yourself