# Profile Lookup - wrong solution

**URL:** <https://forum.freecodecamp.org/t/profile-lookup-wrong-solution/410175>\
**Category:** General\
**Created:** [July 17, 2020, 9:01am UTC](https://forum.freecodecamp.org/t/profile-lookup-wrong-solution/410175 "2020-07-17T09:01:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hubert.br](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hubert.br/32/150350_2.png) [@hubert.br](https://forum.freecodecamp.org/u/hubert.br)\
**Post date:** [July 17, 2020, 9:01am UTC](https://forum.freecodecamp.org/t/profile-lookup-wrong-solution/410175/1 "2020-07-17T09:01:12Z")

</div>

Hi guys,

I was trying to solve Profile Lookup with something like this:

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

```

But it did not pass. Eventually, I looked at the hint telling me to _nest_ my if statements, but I still don’t understand why the code above did not work. Anybody can explain?

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [July 17, 2020, 9:12am UTC](https://forum.freecodecamp.org/t/profile-lookup-wrong-solution/410175/2 "2020-07-17T09:12:08Z")

</div>

when you have a chain like that, one of the statements will always execute, that means that you return a value at first iteration, effectively checking only first element of the array

check better, look that the greatest difference is not that the statements are nested, but that there is a return statement after the loop

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:46pm UTC](https://forum.freecodecamp.org/t/profile-lookup-wrong-solution/410175/3 "2021-06-01T18:46:57Z")

</div>

Closed on June 1, 2021, 6:46pm UTC


