Basic JavaScript: Testing Objects for Properties Code

Basic JavaScript: Testing Objects for Properties Code
0

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

function checkObj(checkProp) {
  // Your Code Here
  if (myObj.hasOwnProperty(checkProp)){
    return myObj.checkProp;
  }else{
    return "Not Found";
  }
}

// Test your code by modifying these values
checkObj("gift");

guys why my code is not working. I know it is a different approach but it all seems to be working.

thanks.


#2

this is the problem i believe.

There is no ‘checkProp’ property in myObj
The available properties that you can access with dot notation are gift, pet and bed.
Try using bracket notation instead of dot notation.


#3

Thanks :grinning: I have searched over the MDN and I found the solution :fu: