Building an Address Book 5/6


#1

what is wrong with my 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]);
}
}

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


#2

@csssolver97046,

Change your

into

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

#3

It says this

SyntaxError: Unexpected token if


#4

is there someting wrong with my if/else statement?


#5

@csssolver97046,
As you are using the ELSE like

else {}

you could leave it out....


#6

it doesnt change anything