Man, I really feel like an idiot. I spent a couple of hours trying to figure this out, just to find that one of my return statements was out of place. Here my original code:
for (i = 0; i < contacts.length; i++) {
if (firstName === contacts[i].firstName) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
} else {
return “No such property”;
}
} else {
return “No such contact”;
}
}
So, I just learned the hard way that I need to loop through each index before returning anything.