Why my code dosen't work what is the difference? Fixed

I found the problem :’) it took me too long. i just forgot the closing bracket of the for loop
this is my code that dosen’t work

function lookUpProfile(name, prop){
    for(var i=0; i<contacts.length;i++){
        
        if(contacts[i]["firstName"] == name){

            if(contacts[i].hasOwnProperty(prop)){
                return contacts[i][prop];
            }else{
                return "No such property";
            }

        }

    return "No such contact";
    }

and this is the answer :slight_smile:

function lookUpProfile(name, prop) {
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].firstName === name) {
      if (prop in contacts[i]) {
        return contacts[i][prop];
      } else return "No such property";
    }
  }
  return "No such contact";
}

so what is the difference why mine dosen’t work is there some kinda bug that i didn’t notice

1 Like
wrong suggestion

if the condition is false, the second one execute - on first iteration of the loop somethin is always returned


I’ve edited your post. If you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

1 Like

ok sorry and the problem was the closing bracket of for loop

1 Like

you are right, sorry for wrong answer

1 Like