Hello campers,
I’ve been struggling with this challenge for quite a while, and now that it seems that my basic knowledge is allowing me to grasp the main idea behind it, my code doesn’t work. I don’t really understand why. Here’s the function the way I wrote it (I have already looked at the solutions, I was just wondering if there’s any way to fix my code).
Thank you stranger/s for reading this!
function lookUpProfile(name, prop) {
for (let i = 0; i < contacts.length; i++) {
const contactItem = contacts[i];
if (name === contactItem.firstName && contactItem.hasOwnProperty(prop)) {
return contactItem[prop];
} else if (name !== contactItem.firstName) {
return 'No such contact';
} else if (!contactItem.hasOwnProperty(prop)) {
return 'No such property';
}
}
}