Profile Lookup errors

Tell us what’s happening:

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)
{
  for(var i=0 ; i <= 3 ; i++)
  {   
    for(var j=0 ; j<=3 ; j++)
    {    if(prop === Object.keys(contacts[i])[j] && name === contacts[i].firstName)
      {
        return Object.keys(contacts[i])[j];
      }break;
      else if(name !== contacts[i].firstName)
      {
        return "No such contact";
      }
      else
      {
        return "No such property";
      }
    }

  }
}


can anyone help on this?
**Link to the challenge:**
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup

Hi Tanuj69,

Things to consider:

  1. Use contacts.length instead of 3 for your loop condition.
  2. Remove the second for loop.
  3. Can’t use && in your if conditional statement as you need to return two things:
    a) return "No such contact";
    b) return "No such property";
  4. Use a nested if instead of if .... else if
    Meaning:
if {
     if {
     }
}