I’m having trouble figuring out why this code is not passing all tests. It’s only failing on “Bob”, “potato”. I assume it’s because it’s leaving the for loop once it hits this iteration, but I’m not sure how to get it to iterate again.
“Kristian”, “lastName” should return “Vos” - passed
“Sherlock”, “likes” should return [“Intriguing Cases”, “Violin”] - passed
“Harry”,“likes” should return an array - passed
“Bob”, “number” should return “No such contact” - passed
“Bob”, “potato” should return “No such contact” - failed
“Akira”, “address” should return “No such property” - passed
Any help would be much appreciated! The relevant code is below:
function lookUpProfile(name, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {
if(contacts[i].hasOwnProperty(prop) && (contacts[i].firstName === name))
{
return contacts[i][prop];
}
else if(!(contacts[i].hasOwnProperty(prop)))
{
return "No such property";
}
}
return "No such contact";
// Only change code above this line
}