title: Profile lookup on freecode camp checkpoint
body: <p>So I'm going through freecodecamp and I'm solving the problems there, to keep in the loop with the programming and I've stumbled on a snag, and I'm not quite sure what's wrong.</p>
  <p>So I have an array of objects called contacts, and I need to create a function called <code>lookUp(firstName, prop)</code>. The text of the assignment is like this:</p>
  <blockquote>
  <p>The function should check if <code>firstName</code> is an actual contact's <code>firstName</code> and the given property (<code>prop</code>) is a property of that contact.</p>
  <p>If both are true, then return the &quot;value&quot; of that property.</p>
  <p>If <code>firstName</code> does not correspond to any contacts then return &quot;No such contact&quot;</p>
  <p>If <code>prop</code> does not correspond to any valid properties then return &quot;No such property&quot;</p>
  </blockquote>
  <p>The code:</p>
  <pre><code>var contacts = [
      {
          &quot;firstName&quot;: &quot;Akira&quot;,
          &quot;lastName&quot;: &quot;Laine&quot;,
          &quot;number&quot;: &quot;0543236543&quot;,
          &quot;likes&quot;: [&quot;Pizza&quot;, &quot;Coding&quot;, &quot;Brownie Points&quot;]
      },
      {
          &quot;firstName&quot;: &quot;Harry&quot;,
          &quot;lastName&quot;: &quot;Potter&quot;,
          &quot;number&quot;: &quot;0994372684&quot;,
          &quot;likes&quot;: [&quot;Hogwarts&quot;, &quot;Magic&quot;, &quot;Hagrid&quot;]
      },
      {
          &quot;firstName&quot;: &quot;Sherlock&quot;,
          &quot;lastName&quot;: &quot;Holmes&quot;,
          &quot;number&quot;: &quot;0487345643&quot;,
          &quot;likes&quot;: [&quot;Intruiging Cases&quot;, &quot;Violin&quot;]
      },
      {
          &quot;firstName&quot;: &quot;Kristian&quot;,
          &quot;lastName&quot;: &quot;Vos&quot;,
          &quot;number&quot;: &quot;unknown&quot;,
          &quot;likes&quot;: [&quot;Javascript&quot;, &quot;Gaming&quot;, &quot;Foxes&quot;]
      },
  ];
  
  
  function lookUp( firstName, prop ){
    for( var i = 0; i &lt; contacts.length; i++ ){
      if( contacts[i].firstName == firstName ) {
        if( contacts[i].hasOwnProperty( prop ) ) {
          return contacts[i].prop;
        } else {
          return &quot;No such property&quot;;
        }
      } else {
        return &quot;No such contact&quot;;
      } 
    }
  }
  
  // Change these values to test your function
  lookUp(&quot;Kristian&quot;, &quot;lastName&quot;);
  </code></pre>
  <p>So I'm looping through the array with <code>for</code> loop checking each object. In the first <code>if</code> I check if the <code>firstName</code> property of that objects equals the function parameter firstName, then if it's true, I check if the object has the property <code>prop</code>, and I should be able to return it. But it seems that</p>
  <pre><code>return contacts[i].prop;
  </code></pre>
  <p>is not working, and I'm kinda lost as to why. I'm sure it's something trivial, but I don't see why. When I go to console, and test</p>
  <pre><code>contacts[0].likes
  </code></pre>
  <p>I get out the array <code>[&quot;Pizza&quot;, &quot;Coding&quot;, &quot;Brownie Points&quot;]</code>, but in my if that's not working. What am I doing wrong here?</p>
  <p><strong>EDIT</strong></p>
  <p>Ok so I tried with</p>
  <pre><code>function lookUp( firstName, prop ){
    for( var i = 0; i &lt; contacts.length; i++ ){
      if( contacts[i].firstName == firstName ) {
        if( contacts[i].hasOwnProperty( prop ) ) {
          return contacts[i][prop];
        } else {
          return &quot;No such property&quot;;
        }
      } else {
        return &quot;No such contact&quot;;
      } 
    }
  }
  </code></pre>
  <p>But I still get the same error :\</p>