Tell us what’s happening:
So first off, I’m trying to do this without the solutions and making my own code - and I’m currently stuck as the tests I’ve run keep coming back with “firstName not defined”. I’m not sure how to define it…or if I’m even on the right track. I’d love any and all help - I’m trying to make more sense of functions and how to write them…
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
for (var i=0; i< contacts.length; i++){
if (contacts[i].firstName === firstName && contacts[i].hasOwnProp(prop))
return contacts[i][prop];
break;
} if
(name !== firstName) {
return "No such contact";
} if
(prop !== value) {
return "No such 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/69.0.3497.100 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup