Why is my answer wrong/ not working

I have been trying to do this task but it doesnt seem to work, however it works for “Akira” “likes”, and these :

// Setup
const 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) {
  // Only change code below this line
for (let x = 0; x < contacts.length; x++ ) {

  if ( contacts[x].firstName !== name) {
    return "No such contact";
  } else if (contacts[x].hasOwnProperty(prop) === false) {
    return "No such property";
  } else {
    return contacts[x][prop];
  }
  
}
  // Only change code above this line
}

console.log(lookUpProfile("Harry", "likes"));

Please use the Ask For Help button so your code is formatted for you and a link to the challenge is automatically added.

1 Like

return statements immediately stop your function

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.