Basic JavaScript - Testing Objects for Properties

Checked all similar issues.
Seems to be exactly the same as the solution and working in VSCode but still does not accepted.

function checkObj(obj, checkProp) {
  // Only change code below this line
  if (obj.hasOwnPropery(checkProp)){
    return obj[checkProp];
  } else {
    return "Not Found";
  }
  // Only change code above this line
}

Your browser information:

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

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

obj.hasOwnPropery(checkProp) check the spelling.

1 Like

HI @skstoqnova !

Welcome to the forum!

In the future, if you are not sure why something isn’t working, you should use console.log to see what your code is doing.

When add a console.log at the bottom of your code, then I get this response which points to the spelling error that was brought up to you.

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

2 Likes

Running the code is the first step to checking it. If you never run the code, it is hard to test it.

I realize the tests run the code for you but you can’t always depend on it giving the same errors as if you run the code manually. Just copy one of the function calls from the tests section and use it in the editor.

1 Like

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