So I have a vague idea what I need to do, but I’m still really lost. I know I need to combine loops, dot/bracket notation and recursion. But I can’t work out how to do that.
I also can’t work out how the loop helps to do the look up? Why is a loop being used for this process, what purpose does it serve to make this work?
// 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 == contacts.hasOwnProperty(firstName) && prop == contacts.firstName){
return prop;
}
return "No such contact";
}
// Only change code above this line
}
lookUpProfile("Akira", "likes");
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Firefox/102.0
Challenge: Basic JavaScript - Profile Lookup
Link to the challenge: