I’m redoing this exercise. It seems like all is okay. The function is not returning the value of the property, though I logged it out (contacts[i][prop]) and looks fine.
for(let i = 0; i < contacts.length; i++) {
if(contacts[i].firstName !== name) {
return 'No such contact'
}
if(contacts[i] !== prop) {
return 'No such property'
}
if(contacts[i].firstName === name && contacts[i] === prop) {
return contacts[i][prop]
}
}//for
With your current logic, your for loop only iterates through the first element in contacts before returning a value. As soon as a return statement is executed, the function is exited (regardless if the loop completed). You have other issues too. You need to think about what contacts[i] represents. You compare it to prop in your second and third if statements, but you should probably console.log each to see what you are really comparing.
for(let i = 0; i < contacts.length; i++) {
if(contacts[i].hasOwnProperty(prop) && name === contacts[i].firstName) {
return contacts[i][prop]
};
if (name !== contacts[i].firstName && (contacts[i].hasOwnProperty(prop) || contacts[i].hasOwnProperty(prop) === false)) {
};
if (name === contacts[i].firstName && (contacts[i].hasOwnProperty(prop) === false)) {
return 'No such property'
};
}//for
return 'No such contact'
One of the returns is placed outside of the for loop so if it is the case that there is No such contact, then it will not impact the return of No such property?