Build a Profile Lookup - Build a Profile Lookup

Tell us what’s happening:

Hey, can you tell what’s wrong with my code, cuz it should work but it keeps stopping after the first object in the array.

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, property) {
  for(const person of contacts) {
    if(name === person.firstName && person.hasOwnProperty(property)) {
    return person[property];
  } else if(name !== person.firstName) {
    return "No such contact";
  } else if(!person.hasOwnProperty(property)) {
    return "No such property";
  }
  }
}
const 
tess = lookUpProfile("Kristian", "lastName");
console.log(tess)

Your browser information:

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

Challenge Information:

Build a Profile Lookup - Build a Profile Lookup

Try to step through how your loop will work.

Keep in mind that return will end the function. A function will only return once.

But the function should choose which if…else condition to follow so it still returns once :thinking:

It returns, exits the function and the program is finished.