Tell us what’s happening:
Describe your issue in detail here.
One thing I really can’t understand about these functions is how does Javascript know to communicate [i] with the contacts list, I’m not sure I’m explaining my confusion. I can’t see how it connects to the list. I know i is arbitrary and declared as a variable starting at 0 and that it checks the contacts length and then does i++ if it hasn’t reached the end so then the i variable will = 1 then 2 etc but what actually tells Javascript that i++ means to iterate through the list?
I can’t complete any of these problems by myself because I don’t understand or know the syntax well enough and I don’t understand how some of these things actually work or function. I went through the course twice up until this point to check if I missed anything but some sections I understand and then one comes along that is totally out of my understanding.
**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 (var i = 0; i < contacts.length; i++) {
if(contacts[i].firstName === name) {
return contacts[i][prop] || "No Such Property";
}
}
return "No Such Contact"
// Only change code above this line
}
var data = lookUpProfile("Kristian", "likes");
console.log(data);
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Profile Lookup
Link to the challenge: