Profile lookup Test

hi, can someone tell me the problem with my code, i am unable to pass the test. see cose below:

function lookUpProfile(firstName, prop) {

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

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

         contacts[i][prop];

        break;

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

        return "No such contact";

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

        return "No such property";

    }

} 

        return contacts;

    

}

Thanks.

can you please provide the challenge link?

like this it’s like you do not have a loop as one of the return statements will execute on first iteration of the loop no matter what - you are checking only first index of the array

In addition, this line does nothing:

contacts[i][prop];

I think you rather want to return contacts[i][prop] at that point.

I have edited your post to include the challenge link.

When you make a post to the forum, make sure to include all of the important information so we can assist you better.

Thank you for helping out.

The link has been added. Thanks.

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