I’m not really sure that @JeremyLT 's explanation is correct
for what I see, your function does not have a return statement as the return statements inside forEach is just for the callback of forEach , not for the lookUpProfile function
ok, I’ve put forEach into variable, so now it looks like
function lookUpProfile(name, prop) {
let lookup = contacts.forEach (contact => {
if (name === contact.firstName) {
console.log(contact.firstName)
if (contact.hasOwnProperty(prop)) {
console.log(contact[prop])
return contact[prop]
} else {return "No such property"}
}
else { return "No such contact"}
})
return lookup
}
Is that correct ? my other question is why I’m getting an undefined in the end of the function
I’m sorry for the confusion - I thought that you were using a for loop. I’d honestly recommend solving these challenges with a basic loop and then try to refactor to fancy high order functions later. Basic loops are ok and you don’t have to use fancy high order functions like forEach just because other people really love them.