Hello,
So I am stuck on this section.
Based on the forums, many others have the “Setup” section of the test but I don’t have that section, and every time I click “Reset All Code”, I get this:
function checkObj(obj, checkProp) {
// Only change code below this line
return "Change Me!";
// Only change code above this line
}
So I tried basing the test on the hints (see code below) and clicked “Ran The Test” but still failed the test.
FAIL MESSAGE: checkObj({pet: “kitten”, bed: “sleigh”}, “gift”) should return the string Not Found
function checkObj(obj, checkProp) {
// Only change code below this line
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
city: "Seattle"
};
if (myObj.hasOwnProperty(checkProp)){
return myObj[checkProp]};
return "Not Found";
// Only change code above this line
}
Any help would be appreciated. Thank you!
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36.
Replace myObj with obj they are handing it in as in argument you do not need to make it in the function. If you are given arguments you will almost always need to make use of them, or else they should not be in the argument list. If you are confused about what certain arguments are you should console.log them
that was the old version of the challenge, this is the new version. What you get is correct
you are always testing the same object, you need to test the functiont argument, not always the same myObj object.
In particular this test fail because you should test the object {pet: “kitten”, bed: “sleigh”} for "gift", and that object does not have the "gift" property
Hello @caryaharper Thank you for pointing that out. I didn’t realize that typo. So I changed the myObj to obj and I still did not pass the test because of the same Fail Message.
FAIL MESSAGE: checkObj({pet: “kitten”, bed: “sleigh”}, “gift”) should return the string Not Found
Hello @ILM
Thanks for the insight. I didn’t realize there was a new version.
I’m still a little confused about the test because if I remove the "gift" property. Then I get this error message:
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift") should return the string pony.
but if I do keep the "gift" property, then I’ll get the same error message:
checkObj({pet: "kitten", bed: "sleigh"}, "gift") should return the string Not Found.
So I guess, I’m still a little confused about this test.
Your answer should consist of the parameters obj, checkProp, a string "Not Found", and JavaScript syntax. You do not need to write gift or pony or kitten or whatever.