Testing Objects For Properties may '21

Tell us what’s happening:
Describe your issue in detail here.
Hehehehe…Oh Please can some wonderful person help and stop me from pulling all my hair out in frustration. I’ve been battling with this exercise for a few hours. All the checks pass except for the last one:
checkObj({pet: "kitten", bed: "sleigh"}, "gift") should return the string Not Found .

Can someone please tell me what am I doing wrong?
Many thanks, Pierson

  **Your code so far**

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

// 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:

Why are you overwriting the argument variable obj with your own object? The function should take an object and a property name and use them.

1 Like

Hi ArielLeslie, thanks for getting in touch. Please forgive my stupidity. Could you show me an example snippet please so I can visually see what you mean. Thanks

the function here has obj as function parameter, that means that the function can get a different value for obj each it is called

that value is lost just two lines below because you overwrite it

ieahleen, thank you. Now I understand what I was doing wrong. I really appreciate both yours and ArielLeslies help . have a great day both.

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