Freecodecamp: [Bug] Basic Data Structures: Check if an Object has a Property

Created on 16 Oct 2018  路  7Comments  路  Source: freeCodeCamp/freeCodeCamp


Describe your problem and how to reproduce it:
Found from this PR https://github.com/freeCodeCamp/freeCodeCamp/pull/19367
The tests are only checking if all the properties exists and another check is done after deleting all the properties so code like:

function isEveryoneHere(obj) {
  return users.hasOwnProperty('Alan', 'Jeff', 'Sarah', 'Ryan'); //shouldnt pass since .hasOwnProperty() doesnt take more than 1 parameter but would only check the first one.
}

and

function isEveryoneHere(obj) {
  return obj.hasOwnProperty("Alan");
}

Passes the challenge whereas they shouldn't.

This can be resolved by adding checks after deleting each property or randomly deleting one and then checking.
Add a Link to the page with the problem:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/check-if-an-object-has-a-property/

Tell us about your browser and operating system:

  • Browser Name: Chrome
  • Browser Version: 69
  • Operating System: 10
learn

All 7 comments

Hey @QuincyLarson @raisedadead, is it fine to accept PR to update the tests to fix this bug?

This issue still persists. hasOwnProperty method doesn't accept multiple parameters, contrary to what has been shown in the lesson. The solution also seems to be incorrect.

Just confirming that this issue is still persisting. if (users.hasOwnProperty('Alan')){ return true; } else { return false; }

will pass the tests.

@razzlestorm It has been fix but not deployed to production.

The guide on this question is also very misleading, basically giving the wrong answer, and since the test is not strict enough people can pass with the wrong answer. Wrong Guide Link
This is probably due to the fact that you could do this with Object.hasOwnProperty
image

And still have true returned.

Students on the forum has got the answer for this question and the proper way of solving the problem here.

@wudifeixue I completely agree with you, so I just created PR https://github.com/freeCodeCamp/freeCodeCamp/pull/36125 which adds two valid solutions to the article.

Keep in mind, even when the PR is merged, you will not see the Guide updated until the current master branch has been deployed to production.

@RandellDawson Awesome, thanks for the super fast pull request too!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

itsmikewest picture itsmikewest  路  3Comments

ar5had picture ar5had  路  3Comments

raisedadead picture raisedadead  路  3Comments

SaintPeter picture SaintPeter  路  3Comments

danielonodje picture danielonodje  路  3Comments