Profile Lookup Property Issue

Tell us what’s happening:
/* All tests run correctly except when the function matches a name with a contact, it won’t check for or return the property of that contact. My guess is there’s somethings wrong with the nested if statement.
*/
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)) {
            return contacts[i].prop;
        }
        else {
            return "No such property";
        }
    }
    else {
        return "No such contact";
    }
}

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36.

Challenge: Profile Lookup

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

Remember that a return statement ends function execution. Because your for loop always hits a return, that means that only the very first element of contacts is checked.

You also have this line:

 return contacts[i].prop;

If you review the challenges about dot notation and bracket notation, you’ll remember that .prop will look for a property with the name “prop” rather than looking up the variable prop.