Build a Profile Lookup - Build a Profile Lookup

Tell us what’s happening:

Hello Community, I am encountering an error here, that I don’t understand. My code (I checked multiple times with MANY logs) should return the correct string, but is getting undefined for some reason I don’t know. Please help me if I overlooked something or if I dipped into a concept I do not yet know. Thank you in advance!

Your code so far

let contacts = [
  {
    firstName: "Akira",
    lastName: "Laine",
    number: "0543236543",
    likes: ["Pizza", "Coding", "Brownie Points"],
  },
  {
    firstName: "Harry",
    lastName: "Potter",
    number: "0994372684",
    likes: ["Hogwarts", "Magic", "Hagrid"],
  },
  {
    firstName: "Sherlock",
    lastName: "Holmes",
    number: "0487345643",
    likes: ["Intriguing Cases", "Violin"],
  },
  {
    firstName: "Kristian",
    lastName: "Vos",
    number: "unknown",
    likes: ["JavaScript", "Gaming", "Foxes"],
  },
];

function lookUpProfile(name, prop) {
  contacts.forEach((contact) => {
    if (contact.firstName === name) {
      return (Object.hasOwn(contact, prop))
        ? contact[prop]
        : "No such property"
    } else return "No such contact"
  })
}

console.log(lookUpProfile("Akira", "address"))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36

Challenge Information:

Build a Profile Lookup - Build a Profile Lookup
https://www.freecodecamp.org/learn/full-stack-developer/lab-profile-lookup/lab-profile-lookup

you have a return for forEach callback, but where do you think is the return for lookUpProfile?

1 Like