From f3e8a0f0c2a415171627368029cc44016fcc9be0 Mon Sep 17 00:00:00 2001 From: Sem Bauke <46919888+Sembauke@users.noreply.github.com> Date: Tue, 18 May 2021 18:36:53 +0200 Subject: [PATCH] fix(curriculum): clarify Check if an Object has a Property (#42156) * fix: clarify Check if an Object has a Property * fix: give extra clarity on object checking --- .../check-if-an-object-has-a-property.md | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/check-if-an-object-has-a-property.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/check-if-an-object-has-a-property.md index ff59bec03f..cbc206b8ab 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/check-if-an-object-has-a-property.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/check-if-an-object-has-a-property.md @@ -19,10 +19,18 @@ Both of these would return `true`. # --instructions-- -We've created an object, `users`, with some users in it and a function `isEveryoneHere`, which we pass the `users` object to as an argument. Finish writing this function so that it returns `true` only if the `users` object contains all four names, `Alan`, `Jeff`, `Sarah`, and `Ryan`, as keys, and `false` otherwise. +Finish writing the function so that it returns true if the object passed to it contains all four names, `Alan`, `Jeff`, `Sarah` and `Ryan` and returns false otherwise. # --hints-- +The `users` object should not be accessed directly + +```js + +assert(code.match(/users/gm).length <= 2) + +``` + The `users` object should only contain the keys `Alan`, `Jeff`, `Sarah`, and `Ryan` ```js @@ -35,13 +43,13 @@ assert( ); ``` -The function `isEveryoneHere` should return `true` if `Alan`, `Jeff`, `Sarah`, and `Ryan` are properties on the `users` object +The function `isEveryoneHere` should return `true` if `Alan`, `Jeff`, `Sarah`, and `Ryan` are properties on the object passed to it. ```js assert(isEveryoneHere(users) === true); ``` -The function `isEveryoneHere` should return `false` if `Alan` is not a property on the `users` object +The function `isEveryoneHere` should return `false` if `Alan` is not a property on the object passed to it. ```js assert( @@ -52,7 +60,7 @@ assert( ); ``` -The function `isEveryoneHere` should return `false` if `Jeff` is not a property on the `users` object +The function `isEveryoneHere` should return `false` if `Jeff` is not a property on the object passed to it. ```js assert( @@ -63,7 +71,7 @@ assert( ); ``` -The function `isEveryoneHere` should return `false` if `Sarah` is not a property on the `users` object +The function `isEveryoneHere` should return `false` if `Sarah` is not a property on the object passed to it. ```js assert( @@ -74,7 +82,7 @@ assert( ); ``` -The function `isEveryoneHere` should return `false` if `Ryan` is not a property on the `users` object +The function `isEveryoneHere` should return `false` if `Ryan` is not a property on the object passed to it. ```js assert( @@ -109,9 +117,9 @@ let users = { } }; -function isEveryoneHere(obj) { +function isEveryoneHere(userObj) { // Only change code below this line - + // Only change code above this line } @@ -140,13 +148,13 @@ let users = { } }; -function isEveryoneHere(obj) { +function isEveryoneHere(userObj) { return [ 'Alan', 'Jeff', 'Sarah', 'Ryan' - ].every(i => obj.hasOwnProperty(i)); + ].every(user => userObj.hasOwnProperty(user)); } console.log(isEveryoneHere(users));