Testing Objects for Properties: what's wrong with my code?

Testing Objects for Properties: what's wrong with my code?
0.0 0

#1

Tell us what’s happening:

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;
  }else{
  return "Not Found";
  }
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties


#2

the ‘dot’ syntax you are using is the problem
you can use the dot syntax if you want to access a known property like
myObj.gift
myObj.pet
myObj.bed

but since checkProp is not the actual literal name of any property, you have to use the bracket notation instead

myObj[checkProp]


#3

Thanks, I have already sorted it