function lookUpProfile(name, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++){
if (contacts[i].firstName === name){
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
} else {
return "No such property";
}
}
return "No such contact"
}
// Only change code above this line
}
lookUpProfile("Sherlock", "likes");
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
Hi ieahleen,
It took quite a while to grasp, but i finally understood that I had to allow all iterations pass and return the “No such contact” as the final function outside of the loop.