Profile Lookup - what wrong am i doing here?

Tell us what’s happening:

Something wrong with my first return statement I guess

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(name === contacts[i].firstName && prop === contacts[i][prop]){
        return contacts[i][prop];
    } else if(name !== contacts[i].firstName){
        return "No such contact";
    } else if(prop !== contacts[i][prop]){
        return "No such property";
    }
}
// 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/66.0.3359.181 Safari/537.36.

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

You’ll usually want to return “No such contact” once you’ve checked all the elements in the array. So the test for } else if(name !== contacts[i].firstName){ should go after the for loop.

you’re not giving your for loop a chance to do any work. You immediately return in your if/else/if/else/if

Try using a boolean variable defined outside the for loop and then setting that depending on what you find in the loop. (but check the result after the loop is done and then return only once).