Hi all, this exercise is driving me crazy. Here’s the link to the challenge: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup
And here’s my solution:
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
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {
if(contacts[i].firstName == name) {
foundName +=1;
}
if(contacts[i].firstName == name && contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
} else if(contacts[i].firstName == name && contacts[i].hasOwnProperty(prop)==false) {
return "No such property";
}
} if (foundName < 1) {
return "No such contact"};
}
var foundName = 0;
// Only change code above this line
// Change these values to test your function
lookUpProfile("Sherlock", "likes");
It’s ticking all of the requirements except 2. It says:
“Bob”, “number” should return “No such contact”
“Bob”, “potato” should return “No such contact”
But I’ve run this a million times in my web browser, storing the result of the function to a variable, and when I access the variable using the above criteria (i.e. “Bob”,"number’ etc) I do get “No such contact”. I can’t work out why this won’t be accepted.