Testing Objects for Properties failed!

Tell us what’s happening:

Not sure I undersnad why the function works for the first property, the error one, but not the second…

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
checkObj("gift");

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

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

Rewrite this line with Bracket notation.

It didn’t resolve the problem =/

Your code works if you switch to bracket notation. Double check that you’ve made the change correctly and post your updated code here if it’s still not passing.

Sorry, I am very new at coding.
If I understood, this would be the bracket notation of it?

// 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”);

1 Like

Your problem is here. There are two issues. Go back to review the lesson on bracket notation, then come back to this.

Thank you, for both GUIDING me, and not simply giving me the answer, cause it helps me learn a lot, and also thank you for taking time helping a noob =)
I’ll go read this lesson again.

Edit : okay, some things are still confuse for me right now but I understood my mistake. thanks again =)