Testing objects for properties,

Tell us what’s happening:
What did I do wrong?

Your code so far


// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
// Only change code below this line
if (myObj.hasOwnProperty(checkProp)) {
return myObj.hasOwnProperty[checkProp];
 } else 
 {return "Not Found"}
// Only change code above this line
}

checkObj("gift");

Your browser information:

User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Mobile/15E148 Safari/604.1.

Challenge: Testing Objects for Properties

Link to the challenge:

If the property is found, return that property’s value

This line:

return myObj.hasOwnProperty[checkProp]
  1. hasOwnProperty is a function, so the syntax is wrong - functions use round brackets
  2. it returns true or false, so even if you’re fix the brackets, it’s the wrong type of thing
  3. You’re not trying to get the value of the hasOwnProperty function, you need to return the value of whatever is assigned to the key represented by checkProp