Basic Data Structures: Check if an Object has a Property has both solutions incorrect

Challenge itself
In this challenge you need to check if “users” object contains ALL four names. Then return “true”. If any of names is missing it should return “false”.
If you press “Get a hint” and look at the solutions, there are two options.

function isEveryoneHere(obj) {
  // change code below this line
  if(users.hasOwnProperty('Alan','Jeff','Sarah','Ryan')) {
    return true;
  }
  return false;
  // change code above this line
}

or

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

While these solutions return “true” and pass the challenge, they are incorrect.
Take a look at this


Both solutions return true. Despite “users” having only one entry. These solutions return “false” ONLY if ‘Alan’ is missing. Other names doesn’t matter to this function.

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

This way it works.

Nope, it doesn’t. Try to remove any of the names, except the last one. And it will still return “true”. I’ve tried your way before, but after some debugging i found that none of these solutions work. I’ve completed this challenge and wrote a correct(but pretty simple and somewhat stupid) solution. But mods should change “solutions” in the guide.

1 Like
function isEveryoneHere(obj) {
  // change code below this line
  return 'Alan' in obj && 'Jeff' in obj && 'Sarah' in obj && 'Ryan' in obj;
  // change code above this line
}

I think this works…

I did this by comparing two (sorted alphabetically) arrays: the required names, and the object keys like this:

function isEveryoneHere(obj) {
    const users = ['Alan', 'Jeff', 'Sarah', 'Ryan'];
    const objKeys = Object.keys(obj);
    // Stringify the sorted arrays and compare them
    return JSON.stringify(users.sort()) === JSON.stringify(objKeys.sort());
}

The solution does need to be changed, not sure how we can go about getting that done. Maybe as a github issue?

Hi there, I was trying this too and also found that both solutions are incorrect… if you follow the solutions given in the hint, you can easily “pass” the challenge, but only the first name needs to be present for it to return true. As you can see in this screenshot:

Agree that the solution needs to be changed.

Edit: In another post a wiser user has shared some alternatives: