What can be added in the code below, so that
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift")
should return the string pony
.
and in the same time,
checkObj({pet: "kitten", bed: "sleigh"}, "gift")
should return the string Not Found
.
*It sounds a bit counter-intuitive to me to meet both of those requirements, by manipulating only the interior of the function*
function checkObj(obj, checkProp) {
var obj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
city: "Seattle"
};
if (obj.hasOwnProperty(checkProp)) {
return obj[checkProp];}
else {
return "Not Found";};
}
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36
Challenge: Testing Objects for Properties
Link to the challenge: