Basic JavaScript: Profile Lookup doesn't work

Tell us what’s happening:
It fails to return the property of the contact when the contact name is right and it has that property.

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(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) == true) {
    return contacts[i][prop];
} else {
    return "No such property";
}

}
return "No such contact";
}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Sherlock", "likes");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36.

Challenge: Profile Lookup

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup

It might be helpful to highlight that when the function finds a return statement, its execution is stopped. If you consider this and walk through the for loop one step at a time you might notice the issue:

// "Sherlock", "likes"
function lookUpProfile(name, prop) {
   // loop through the array
   for (var i = 0; i < contacts.length; i ++) {
      // first item: "Sherlock" === "Akira"
      // false, the if statement does not run ...
      if (contacts[i].firstName === name ) {
         if (contacts[i].hasOwnProperty(prop) == true) {
            return contacts[i][prop];
         } else {
           return "No such property";
         }
      } 
      return "No such contact";
   }
}

So what does actually happen in your example?

Your Input: "Sherlock", "likes"

for (var i = 0; i < contacts.length; i ++) {
if (contacts[i].firstName === name ) {}
return "No such contact";

In this case, firstName is Akira and not Sherlock,
so it returns No such contact.