Basic JavaScript - Profile Lookup1

Tell us what’s happening:

What am I doing wrong? I don’t know what to do…

Your code so far

// 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 i = 0; i < contacts.length; i++) {
  if (name.value === contacts.firstName && contacts.hasOwnProperty(prop)) {
    return contacts.prop;
  }
} 
if (name !== contacts.firstName) {
  return "No such contact";
} else if (!contacts.hasOwnProperty(prop)) {
return "No such property";
}
  // Only change code above this line
}

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

Your browser information:

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

Challenge Information:

Basic JavaScript - Profile Lookup

Hi, having a look now.

First issue:

name.value is not a thing.

name is only a string like “Akira” no value property on it.

Try in your browser’s console “Akira”.value … that will return undefined.

Second issue:
contacts is an array.

This check should be in the loop probably.

if (name !== contacts.firstName) {
  return "No such contact";
} else if (!contacts.hasOwnProperty(prop)) {
return "No such property";
}

outside of the loop and with this accessor on the contacts array is not going to work.

If you want to make the check outside of the loop then capture the contact found in a variable in the function scope.

contacts is an array of objects with firstName. ← this is the important clue

Third issue:
The logic inside the loop is not correct.