* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2.2 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
567af2437cbaa8c51670a16c | Testing Objects for Properties | 1 | https://scrimba.com/c/c6Wz4ySr | 18324 | 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.
Example
var myObj = {
top: "hat",
bottom: "pants"
};
myObj.hasOwnProperty("top"); // true
myObj.hasOwnProperty("middle"); // 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"
.
--hints--
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift")
should return "pony"
.
assert(
checkObj({ gift: 'pony', pet: 'kitten', bed: 'sleigh' }, 'gift') === 'pony'
);
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet")
should return "kitten"
.
assert(
checkObj({ gift: 'pony', pet: 'kitten', bed: 'sleigh' }, 'pet') === 'kitten'
);
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house")
should return "Not Found"
.
assert(
checkObj({ gift: 'pony', pet: 'kitten', bed: 'sleigh' }, 'house') ===
'Not Found'
);
checkObj({city: "Seattle"}, "city")
should return "Seattle"
.
assert(checkObj({ city: 'Seattle' }, 'city') === 'Seattle');
checkObj({city: "Seattle"}, "district")
should return "Not Found"
.
assert(checkObj({ city: 'Seattle' }, 'district') === 'Not Found');
checkObj({pet: "kitten", bed: "sleigh"}, "gift")
should return "Not Found"
.
assert(checkObj({ pet: 'kitten', bed: 'sleigh' }, 'gift') === 'Not Found');
--seed--
--seed-contents--
function checkObj(obj, checkProp) {
// Only change code below this line
return "Change Me!";
// Only change code above this line
}
--solutions--
function checkObj(obj, checkProp) {
if(obj.hasOwnProperty(checkProp)) {
return obj[checkProp];
} else {
return "Not Found";
}
}