Object Property Check

I pass in the object users as an argument for isEveryoneHere function and to match and check each property name, but it’s not working.

Here is my code:

let users = {
  Alan: {
    age: 27,
    online: true
  },
  Jeff: {
    age: 32,
    online: true
  },
  Sarah: {
    age: 48,
    online: true
  },
  Ryan: {
    age: 19,
    online: true
  }
};

function isEveryoneHere(userObj) {
  // Only change code below this line
  if (users.hasOwnProperty("Alan" && "Jeff" && "Sarah" && "Ryan")){
    return true;
  } else return false;
  // Only change code above this line
}

console.log(isEveryoneHere(users));

Here is the link https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-data-structures/check-if-an-object-has-a-property

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Here you pass in the userObj

And here you are not using it.

Also, hasOwnProperty doesn’t work like that.

It is confusing to mix if-else clauses with and without braces. It is recommended to pick one (usually braces) and stick with it.

1 Like

Figured it out. Thanks, Jeremy!

1 Like