Tell us what’s happening:
Describe your issue in detail here.
I have been trying it for hours, but I still can’t figure out why it doesn’t work. I used a for ... of loop for this challenge. Could someone help me with the code below, please?
**function lookUpProfile(name, prop) {
for (let contact of contacts) {
if (contact.firstName === name) {
return contact[prop] || "No such property";
}
return "No such contact";
}
}
lookUpProfile("Sherlock", "likes");**
// 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 contact of contacts) {
if (contact.firstName === name) {
return contact[prop] || "No such property";
} return "No such contact";
}
// Only change code above this line
}
lookUpProfile("Sherlock", "likes");
**Your browser information:**
User Agent is: Chrome/104.0.0.0
Challenge: Basic JavaScript - Profile Lookup
Link to the challenge: