freeCodeCamp Challenge Guide: Testing Objects for Properties

Testing Objects for Properties


Hints

You do not need to declare any additional variables or define any objects inside of your function. You must use the function arguments obj and checkProp.

Note: Old solutions found in replies to this post will not work. This challenge has been edited several times since 2017. Only the solution in this post is up to date.


Solutions

Solution 1 (Click to Show/Hide)

function checkObj(obj, checkProp) {
  if (obj.hasOwnProperty(checkProp)) {
    return obj[checkProp];
  } else {
    return "Not Found";
  }
}
192 Likes