5/6 Help


#1

I keep getting this error "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? "
"TypeError: Cannot read property 'lastName' of undefined"

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

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

search("Jones");

I dont get where im messing up


#2

You are directly closing the FOR-code-block,
and therefor your IF-statement is NOT included in the FOR-loop.....


#3

You got a mean sneaky bracket hidden over there (the one that is bolded):

Three brackets at the end, not 2.

Okay, @leonhard_wettengmx_n just said what I was about to say. It works :smiley:

--SO--

That bracket over there is messing you up, as @leonhard_wettengmx_n had said. Closing that for loop is making no use of the for loop, nor can you use the for loop at all, if there's nothing in those brackets.