Dot notation vs. bracket: Basic JavaScript - Testing Objects for Properties

Tell us what’s happening:
Describe your issue in detail here.
So I peeped the solution and saw that the only issue I had was I was using dot notation instead of bracket. Can someone explain why dot notation doesn’t work here?

Your code so far

function checkObj(obj, checkProp) {
  // Only change code below this line
  if (obj.hasOwnProperty(checkProp)) {
    return obj.checkProp;
  }
  else {
    return "Not Found"
  }
  // Only change code above this line
}
console.log(checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift"))

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

Dot notation only works with the exact, literal name of the property. You aren’t looking for a property literally called checkProp.

Got it! Thank you again :pray:

1 Like

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