Tell us what’s happening:
Hello,
I am getting an error on
"Bob", "potato"
should return “No such contact”
even thought the one prior to that with the name Bob is written the same way.
Thanks,
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(firstName, prop){
var msg = 'No such contact';
for (var p in contacts) {
if (contacts[p].firstName === firstName && contacts[p].hasOwnProperty(prop)) {
msg = contacts[p][prop];
} else if (!contacts[p].hasOwnProperty(prop)) {
msg = 'No such property';
}
}
return msg;
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Harry", "likes");
lookUpProfile("Bob","number");
return msg "No such contact"
lookUpProfile("Bob","potato");
return msg "No such contact"
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup