What's the issue here?


#1

I'm trying to figure out why my code won't work. I keep getting the error message : "It looks like your search function didn't log "Bob Jones" to the console. Did you remember to call search after you defined 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]);
}
}

var search = function(lastName){
var contactsLength = contacts.length;
for (var i = 0; i < contactsLength; i++){
if (contacts[i].lastname === lastName){
printPerson(contacts[i]);
}
else{
console.log("Contact not found.");
}
}
};

search("Jones");

`


#2

Consider how your program's behavior differs from what you intend and what could be causing that difference.

Use console.log to help you. For example, you can log out your contacts and see if Bob is there, if he's not, then that would explain why he's not found and then you'll have to look at the piece of code that's meant to add Bob to the contacts.

Make your log's print out what the program is doing, as if it were explaining to you what it does.


#3

That sorta makes sense, but what exactly would I tell the log to print for me?


#4

Search function was called, last name to find is: Jones
The contacts are: { ... }
currently looking at: aoetnsuhao
that was a match/mismatch
..