if (contacts[i]["firstName"] == name) {
if (contacts[i].hasOwnProperty(prop)) return contacts[i][prop];
else return "No such property";
}
return "No such contact";
You are checking if the the first name matches. If the first name doesn’t match, what are you doing? You are deciding that the contact doesn’t exist and are exiting the function. After the first contact doesn’t match!
So, instead of deciding the contact doesn’t exist there, can you think of a better place? When I make that change, your code passes.
are you able to tell if the contact exist or not after just looking at first contact? you need to put the return statement outside so that you actually let the loop look theough all the array
The other thing I might say is to pick some input data and mentally step through your algorithm, predicting what it will do. This is a great way to learn how to think.