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



    if (name=== contacts[i]["firstName"] && contacts[i].hasOwnProperty(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");

Can you be more specific about what is not working? The for loop is working fine. The problem appears to be that you only iterate through the first element (contact) in the contacts array before returning a value. Return statements cause the function to exit immediately. Think about when you should really return each value and you will figure this out.

@ale1a1 , Welcome to the FCC community.

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