Instructions
Modify the function checkObj to test myObj for checkProp. If the property is found, return that property’s value. If not, return “Not Found”.
Had this exact same problem. Why does the checkProp not end up being a variable in the dot example but in the bracket example it ends up being a variable?
Woah I did it completely different and passed the test… … I understand the challenge was to use the “.(propname)” I was confused on the way it was explained soooo I tinkered around and did it like this
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty(checkProp) === true) {
return myObj[checkProp];
} else {
return "Not Found";
}
}
// Test your code by modifying these values
checkObj("gift");
I have a similar solution as you but I left out the === true since an if statement always results in a true or false statement.
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty(checkProp)){
return myObj[checkProp];
} else
return "Not Found";
}
// Test your code by modifying these values
checkObj("gift");
Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, instead of posting a full solution, give the OP hints and suggestions unless the OP has already indicated a solution has been found.