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:
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
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!