Profile Lookup challenge (Basic Javascript)

Profile Lookup challenge (Basic Javascript)
0

#1

Hi all, I am running on a problem with profile lookup challenge.
Can someone explain why I wrong?
Here is my code:

function lookUpProfile(name, prop){
// Only change code below this line
    for (var i = 0 ; i < contacts.length; i++) {
      if (name === contacts[i].firstName) {
          if (contacts[i].hasOwnProperty(prop) === true) {
            return contacts[i][prop];
          }
          else return "No such property";
      }
      else
      {
        return "No such contact";
      }
    }
// Only change code above this line
}

Thank you very much.


#2

You are only checking the the first contact in the list. If its name doesn’t match, you return "No such contact" and never check any other items.


#3

Thanks for your help and explanation.
I have just resolved that problem.