Basic JavaScript - Testing Objects for Properties

Tell us what’s happening:
Hi all, I am working on a Javascript basic task
I have also tried another way, which is to declare the object within the function, but there is a conflict of “gift” which is first declared so, it has a value and then in the last check must return “not found”. I then consulted forums and youtube, and the code seems to be what I posted below. But it doesn’t work, it gives me the following errors.
// running tests

checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house")
```should return the string```
Not Found

checkObj({city: "Seattle"}, "district") should return the string
Not Found

checkObj({pet: “kitten”, bed: “sleigh”}, “gift”)
should return the string
Not Found
. // tests completed

Your code so far


  function checkObj(obj, checkProp) {
  // Only change code below this line
  if (obj.hasOwnProperty){
    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/110.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

(checkProp)! what a distraction! Thanks

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