Testing Javascript Objects for Properties

Tell us what’s happening:
var Obj = {

gift: "pony",

pet: "kitten",

bed: "sleigh",


myObj.hasOwnProperty(checkProp); {

return myObj[checkProp]; 


return “Not Found”;

// Only change code above this line


Your code so far

function checkObj(obj, checkProp) {
// Only change code below this line
function checkObj(checkProp){
  return myObj.hasOwnProperty(checkProp)===true?myObj[checkProp]: "Not Found";
// Only change code above this line

i dont know how else i am supposed to write this code, i need help

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36.

Challenge: Testing Objects for Properties

Link to the challenge:

A few things:

  • You are defining a new function inside of the original checkObj function but you aren’t actually calling this new function so it isn’t really doing anything. Since the original checkObj function isn’t explicitly returning a value, it returns undefined. This is one reason why the tests aren’t passing. You don’t need to define a new function inside of checkObj to complete this exercise. You just need the return statement.
  • The return statement is almost correct except that it is not referencing the obj passed into checkObj. The first argument passed into checkObj is the object you want to test. That is the object you want to be referencing in your return statement.

return obj.hasOwnProperty(checkProp) ? obj[checkProp] : “Not Found”;

This is the return statement with the ternary style. Here is the MDN page: I really like using this style as opposed to the if / else, like in the hint and solution video. Good on you for going the extra step.