Check if an Object has a Property Questionnn

Tell us what’s happening:
Before attempting this challenge I checked on google if hasOwnProperty accepts more than one property at once and apparently it doesnt, it will only consider the first property entered, so I solved the problem as listed below. However afterwards I checked the solutions listed for this lesson and it is checking for multiple properties at once with hasOwnProperty. Am I missing smth or is the solution provided wrong?

function isEveryoneHere(obj) {
  return (users.hasOwnProperty('Alan','Jeff','Sarah','Ryan')) ? true : false;
}

Your code so far


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

function isEveryoneHere(obj) {
  // change code below this line
 return obj.hasOwnProperty('Alan') && obj.hasOwnProperty('Jeff') && obj.hasOwnProperty('Sarah') && obj.hasOwnProperty('Ryan') ? true : false;

  // change code above this line
}

console.log(isEveryoneHere(users));

Your browser information:

User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/check-if-an-object-has-a-property

1 Like

Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.

You’re right. One of the solutions in the Guide is incorrect. If you would like to submit a PR and correct it yourself, this is very easy to do. Otherwise, could you please create a GitHub Issue?

2 Likes