Testing Objects for Properties, Code not running,

Tell us what’s happening:
I’ve put checkProp within double quotes when checking with hasOwnProperty as that’s what they demonstrated in the example code given in FreeCodeCamp. Do they have an instructor to help people out with doubts?

Your code so far

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

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

// Test your code by modifying these values

Your browser information:

You can always ask in the forum if you have doubts

In the example they show you how to check for a property using directly the property name.
You instead have a variable called checkProp with value of a string, and you have to check if that value is a property or no.

The issue is that if you write "checkProp", that is a string, and there is no object property called like that. If you instead use checkProp, which is a variable, it will be evaluated and the value that the variable holds will be used

1 Like