Hi Everyone,
I have the following requirements for the completion of this task:
-
Passed:
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift")
should return the stringpony
. -
Passed:
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet")
should return the stringkitten
. -
Passed:
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house")
should return the stringNot Found
. -
Passed:
checkObj({city: "Seattle"}, "city")
should return the stringSeattle
. -
Passed:
checkObj({city: "Seattle"}, "district")
should return the stringNot Found
.
Failed: checkObj({pet: "kitten", bed: "sleigh"}, "gift")
should return the string Not Found
.
Now, is it even possible to make gift return and not return at the same time?
If the
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift")
should return the string pony
.
task is completed, then the
“checkObj({pet: "kitten", bed: "sleigh"}, "gift")
should return the string Not Found
.”
task is bound to fail, isn’t it?
Thank you in advance for your help.
function checkObj(obj, checkProp) {
// Only change code below this line
const myObject = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
city: "Seattle",
}
if (myObject.hasOwnProperty(checkProp)) {
return myObject[checkProp];
}
return "Not Found"
}
// Only change code above this line
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0
Challenge: Basic JavaScript - Testing Objects for Properties
Link to the challenge: