Profile Lookup Challenge - help!

Hello campers,

I’ve been struggling with this challenge for quite a while, and now that it seems that my basic knowledge is allowing me to grasp the main idea behind it, my code doesn’t work. I don’t really understand why. Here’s the function the way I wrote it (I have already looked at the solutions, I was just wondering if there’s any way to fix my code).

Thank you stranger/s for reading this!

function lookUpProfile(name, prop) {

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

    const contactItem = contacts[i];

    if (name === contactItem.firstName && contactItem.hasOwnProperty(prop)) {

      return contactItem[prop];

    } else if (name !== contactItem.firstName) {

      return 'No such contact';

    } else if (!contactItem.hasOwnProperty(prop)) {

      return 'No such property';




Remember, when you use a return statement the function exits immediately. All three conditions in your function have a return statement, so you never make it past the first loop. One of those return statements you want to save until after you have exhausted the for loop.

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