For loop not working

Hi there

Can someone help me to understand why the for loop inside the function is not working?

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){

for (var i=0; i<contacts.length; i++) {

    console.log(i)

    

    if (name=== contacts[i]["firstName"] && contacts[i].hasOwnProperty(prop)) {

        console.log(contacts[i][prop]);

        return contacts[i][prop]

    } else if (name!== contacts[i]["firstName"]) {

        console.log("No such contact");

        return "No such contact";

    } else if (contacts[i].hasOwnProperty(prop)== false) {

        console.log("No such property");

        return "No such property";

    }

}

}

lookUpProfile("Kristian", "lastName");

@ale1a1 , Welcome to the FCC community.

I don’t see why your code isn’t working. provide more code if possible.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.