Tell us what’s happening:
Hi,
I’m not sure about naming my variables that I’ll use in my for loops. I know I want to go through the array of objects to check for the name and the prop. I think my instructions that I wrote for myself give a good idea of how im thinking about the problem. Thanks for feedback
Your code so far
//Setup
var 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
//Name parameter is firstName, check to see if it's the contact's real first Name using a for loop
//if no, 'No such contact'
// prop is a parameter, check if prop is a property of the contact using a for loop
//if no, 'No such property'
//If both are true, return the value of the property
var property =prop;
var name = firstName;
for (var i=0; i <contacts.length; i++){
if (name !== contacts[firstName]){
return 'No such contact';
}
for (var i=0; i<contacts.length; i++){
if(property !== contacts[name][property]){
return 'No such property';
}
}
return contacts[name][property];
}
// Only change code above this line
// Change these values to test your function
lookUpProfile("Akira", "likes")
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup