Finding that special one


#1

I don't know what I'm doing wrong. Can anyone help?

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

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

};

search("Jones");


#2

Try to format it properly
1) copy and paste your code
2) highligt/select your whole code
3) then look for this </> and press it.
or
simply press ctrl + shift + c and past the code inside the highlighted area.
There is lot of syntax error so first look at last 6th line you dont need "}" at the end second you also dont need else statement because dont have any thing inside it third you need two "}" after end of else statement.


#3

I figured out the mistake! I missed one curly brace.
Anyways thanks!