Help with Basic Objects

Hi there. I am just curious as to why this code won’t work?

function checkObj(obj, checkProp) {
  if (obj.hasOwnProperty(checkProp)) { // Check if obj has checkProp as a property
    return checkProp; // Return checkProp if it exists
  } else {
    return "Not Found"; // Return "Not Found" if checkProp does not exist
  }
}

Describe your issue in detail here.

Your code so far

function checkObj(obj, checkProp) {
  // Only change code below this line
  return "Change Me!";
  // 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/111.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

If the property is found, return that property’s value. If not, return "Not Found".

This is asking you to return the value associated with the property checkProp, not the name of the property.

In this problem, you need to extract the value associated with that property that is housed inside the object. Please take a look on bracket notation and dot notation for a better understanding on how to extract such value :wink:

checkprop on it’s own doesn’t exist. It is a property of the object. You have to tell it which object in which to find checkprop .

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