Profile Lookup - 2nd Version change in order of operations to test for invalid cases first

Tell us what’s happening:
I can get the solution to work using the standard answer. Now I wanted to test for the invalid items first so I rewrote the code.

pseudocode

for each X in array
Check for name; if not found return “no name found”

Check if the property isn’t valid; return “not a valid prop”
else
return prop and name

What am I missing? It is like it isn’t progressing through the loop or something?!

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){
    
    console.log("First Step")
    for (var counter = 0; counter < contacts.length; counter++) {
        console.log(contacts[counter]["firstName"]);

        if (name != contacts[counter]["firstName"]) {
            return "No such contact";
            }
        console.log("step two")

        if (contacts[counter].hasOwnProperty(prop)) {
            return contacts[x][prop];
        } else {
            return "No such property";
            }
    }
}

// Change these values to test your function
console.log(lookUpProfile("Kristian", "lastName"));
console.log(lookUpProfile("Sherlock", "likes"));


Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 12105.53.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.61 Safari/537.36.

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

That is an assignment operator, you are assigning the value of property firstName to variable name

Also, remember that a return statement breaks from the function - are you sure you want to put that if statement there?

Updated to the correct version sorry.

Hmmm not sure what to do about the return statements…

Consider when you need to say that there is no such contact

Right now your code is checking just first element in the array - but you need to check them all, right?

Also, in case you remove that return statement, there is the other if statement , that with that condition will check the first element independently if the name match