Object hasOwnProperty is used in wrong way in freecodecamp's hint module

Object hasOwnProperty is used in wrong way in freecodecamp's hint module
0

The question asks to return true only if the object has all 4 mentioned properties.
And in hint section, the solution given as

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

This is wrong as the hasOwnProperty takes only 1 argument and ignores the rest. So it is just checking for Alan property and giving out the result based on if it is present in object or not.

The correct solutions are:

return ["Alan", "Jeff", "Sarah", "Ryan"].every(e =>
          users.hasOwnProperty(e)
        );

        return (
          users.hasOwnProperty("Alan") &&
          users.hasOwnProperty("Jeff") &&
          users.hasOwnProperty("Sarah") &&
          users.hasOwnProperty("Ryan")
        );

        return (
          "Alan" in users &&
          "Jeff" in users &&
          "Sarah" in users &&
          "Ryan" in users
        );

I hope this gets corrected it soon.

1 Like

An issue for this on Github appears to have been closed. It might be worthwhile if you could add your comment to the existing issue, or create a new one:

If it’s closed it is probably fixed in beta (freecodecamp.rocks)

Yeah, I wondered that but couldn’t check on mobile easily.

Oh, not fixed

1 Like