# Profile lookup strange solution

**URL:** <https://forum.freecodecamp.org/t/profile-lookup-strange-solution/156285>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [October 31, 2017, 11:24pm UTC](https://forum.freecodecamp.org/t/profile-lookup-strange-solution/156285 "2017-10-31T23:24:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oletem](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/oletem/32/161112_2.png) [@Oletem](https://forum.freecodecamp.org/u/Oletem)\
**Post date:** [October 31, 2017, 11:24pm UTC](https://forum.freecodecamp.org/t/profile-lookup-strange-solution/156285/1 "2017-10-31T23:24:38Z")

</div>

I have used hasOwnProperty() for this for the first time,

but I have been revising material lately and have run into quite a strange solution. Can someone

explain to me how I am getting “No such property” output, please? Am I right in my guess (in comments)?

Thanks in advance

```auto
//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(firstName, prop){

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

    
  if(contacts[i].firstName == firstName){
    
    if(contacts[i][prop]==firstName[prop]){
      
     return "No such property";/*How does it parses as correct, does it return "No such property" 
     
     only if (contacts[i][prop]==firstName[prop]) evaluetes to false, skipping it otherwise? */
     }
    
        return contacts[i][prop];
  }// nested if part ends returning props array
      
  }//for part ends 
  
  return "No such contact";// Last output, because for loop has to parse all contacts parts before output it
  }

// Change these values to test your function
lookUpProfile("Harry", "likes");

```

---

<div class="post-metadata">

**Author:** ![v-lai](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/v-lai/32/65024_2.png) [@v-lai](https://forum.freecodecamp.org/u/v-lai)\
**Post date:** [November 1, 2017, 1:25am UTC](https://forum.freecodecamp.org/t/profile-lookup-strange-solution/156285/2 "2017-11-01T01:25:13Z")

</div>

You are getting “No such property” when you are returning it at the last line of that function.

This `if(contacts[i][prop]==firstName[prop])` line is unnecessary, as it doesn’t do anything. `firstName` is a string and not an object, so you’re asking if `contacts[i][prop]==undefined` which won’t ever be the case.

---

<div class="post-metadata">

**Author:** ![Oletem](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/oletem/32/161112_2.png) [@Oletem](https://forum.freecodecamp.org/u/Oletem)\
**Post date:** [November 1, 2017, 9:14pm UTC](https://forum.freecodecamp.org/t/profile-lookup-strange-solution/156285/3 "2017-11-01T21:14:04Z")

</div>

Thanks, I understand that. But why FCC consider my code to be correct, if I am not even checking the prop value in second if?

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [January 18, 2021, 8:24am UTC](https://forum.freecodecamp.org/t/profile-lookup-strange-solution/156285/4 "2021-01-18T08:24:15Z")

</div>

Closed on January 18, 2021, 8:24am UTC


