Basic JavaScript - Testing Objects for Properties

Tell us what’s happening:
Describe your issue in detail here.

I understand the example for this exercise but not the answer.

why would we check obj for checkProp?
shouldn’t we be checking checkObj.hasOwnProperty[checkProp] ?

This confuses me. What am I not understanding 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

Link to the challenge:

In this exercise, we are tasked with modifying a function checkObj that takes two arguments. The first argument, obj , is the object we want to check, while the second argument, checkProp, is a string that is the property we want to check our object for.

That is why we want to check obj.hasOwnProperty(checkProp) inside the if statement. We are checking if the object passed into the function checkObj has the property name passed in as the second argument, checkProp.

you need to check the passed in object, checkObj is the function
also you can’t use square parenthesis, as hasOwnProperty is not an array

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