fix(curriculum): Be more explicit about using parameters (#50269)

This commit is contained in:
Lasse Jørgensen
2023-05-05 13:25:38 +02:00
committed by GitHub
parent a52b13c17e
commit 1b69bbdaef

View File

@@ -8,25 +8,24 @@ dashedName: testing-objects-for-properties
# --description--
Sometimes it is useful to check if the property of a given object exists or not. We can use the `.hasOwnProperty(propname)` method of objects to determine if that object has the given property name. `.hasOwnProperty()` returns `true` or `false` if the property is found or not.
To check if a property on a given object exists or not, you can use the `.hasOwnProperty()` method. `someObject.hasOwnProperty(someProperty)` returns `true` or `false` depending on if the property is found on the object or not.
**Example**
```js
const myObj = {
top: "hat",
bottom: "pants"
};
function checkForProperty(object, property) {
return object.hasOwnProperty(property);
}
myObj.hasOwnProperty("top");
myObj.hasOwnProperty("middle");
checkForProperty({ top: 'hat', bottom: 'pants' }, 'top'); // true
checkForProperty({ top: 'hat', bottom: 'pants' }, 'middle'); // false
```
The first `hasOwnProperty` returns `true`, while the second returns `false`.
The first `checkForProperty` function call returns `true`, while the second returns `false`.
# --instructions--
Modify the function `checkObj` to test if an object passed to the function (`obj`) contains a specific property (`checkProp`). If the property is found, return that property's value. If not, return `"Not Found"`.
Modify the function `checkObj` to test if the object passed to the function parameter `obj` contains the specific property passed to the function parameter `checkProp`. If the property passed to `checkProp` is found on `obj`, return that property's value. If not, return `Not Found`.
# --hints--