Run does not pass

Tell us what’s happening:
Describe your issue in detail here.

Hi, I have problem passing the run.
If gift is "pony"then why does it say:
checkObj({pet: "kitten", bed: "sleigh"}, "gift") should return the string Not Found .?
since gift: “pony”, is included in the objects.
any help would be appreciated.
Thanks
Your code so far


function checkObj(obj, checkProp) {
// Only change code below this line
var checkObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
city: "Seattle"
};
if (checkObj.hasOwnProperty(checkProp))  {
return checkObj[checkProp];
} else {
return "Not Found";

}
return "Change Me!";
// Only change code above this line
}
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36

Challenge: Testing Objects for Properties

Link to the challenge:

Hi @aceal.haider

It is because you are checking the property in the hard coded object not in the passed object. It should be something like:

if (obj.hasOwnProperty(checkProp))  {

} else {
}

You don’t need checkObj and the last return statement.

1 Like

Thank you for the feedback, I don’t know I changed something and it worked lol. I really appreciate your feedback. it was kind of weird. I changed it to “obj” and “checkObj” nothing worked :smiley: Thank you again.
Best,
Aceal

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.