Can someone please help me understand what it is that I am missing in my logic here? I found answers to this problem that use logic to make it shorter, but I am just trying to understand how to put it together properly if I just go down the list of things to do and write the code. Without making it more complicated by putting step 3 first and stuff like that. What is wrong with my logic/code?
The first if statement works fine until I add additional else if statements to it. As soon as I add the second if statement, the former if statement doesn’t work anymore. Why?
for (var i = 0; i < contacts.length; i++) {
if (name === contacts[i].firstName && contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
} else if (name !== contacts[i].firstName) {
return "No such contact";
} else if (!contacts[i].hasOwnProperty(prop)) {
return "No such property";
}
}
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
.