Profile lookup (value of a property)

Tell us what’s happening:
Describe your issue in detail here.
Hello, this is what I have written so far and I am not sure if I am on the right track or not but I was wondering if someone could help me with returning the value of a property. I can’t find the challenge this topic was addressed in.

  **Your code so far**

// 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(name, prop) {
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {
  if (contacts[i][firstName] === name && contacts[i].hasOwnProperty(prop) = true) {
// Only change code above this line

lookUpProfile("Akira", "likes");
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36

Challenge: Profile Lookup

Link to the challenge:

= is not checking equality here. == or === checks equality.

Also, hasOwnProperty returns true or false so you don’t need to check equality with it. Just:

&& contacts[i].hasOwnProperty(prop))
1 Like

do we only check equality if it is false? because in the solution of another challenge, there was a statement with hasOwnProperty followed by === false.

It depends on the case.

In an if statement, the code happens if true.

if (what is here is true) {
        then do something

If you want to do something if you expect the result to be false you need to make a false result evaluate to true in this case

Is one way, another way is to use the logical not operator

// you want to do something if it does not have prop
if (!hasOwnProperty(prop))
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.