Tell us what’s happening:
A lookUpProfile
function that takes name
and a property ( prop
) as arguments has been pre-written for you.
The function should check if name
is an actual contact’s firstName
and the given property ( prop
) is a property of that contact.
If both are true, then return the “value” of that property.
If name
does not correspond to any contacts then return "No such contact"
.
If prop
does not correspond to any valid properties of a contact found to match name
then return "No such property"
.
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
if(name ==contacts[name].firstName && prop == contats[name].prop)
return contacts[name][prop]
else if(name !== contacts[name]){
return 'No such property';
}else if(name ==contacts[name].firstName && prop !== contats[name].prop)
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 (X11; CrOS x86_64 12607.82.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.123 Safari/537.36
.
Challenge: Profile Lookup
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup