I’v rewritten this function several times, I cannot find the mistake:
function lookUpProfile(firstName, prop){
// Only change code below this line
for(var i = 0; i < contacts.length; i++){
if(firstName === contacts[i].firstName){
if(contacts[i].hasOwnProperty(prop)){
return contacts[i][prop];
}else{
return "No such property";
}
}else{
return "No such contact";
}
}
}
HI,
I did not know if that’s ok (too messy?), but I did in a different way.
function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++){
var isProp = contacts[i].hasOwnProperty(prop);
if (firstName === contacts[i].firstName && isProp){
return contacts[i][prop];
} else if (isProp === false){
return "No such property";
}
}
if (firstName !== contacts.firstName){
return "No such contact";
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Harry", "likes");