Basic JavaScript - Testing Objects for Properties

Tell us what’s happening:
I have not been able to pass the code

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
}
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift");

Your browser information:

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

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

please check if other similar questions and/or solutions before posting another! This is from today: Basic JavaScript - Testing Objects for Properties

Hi @Agada,

You are more than welcome to post your own topic about the same challenge because you have your own problems with that same challenge. So, don’t worry about that.

Check out this line:

 if (obj.hasOwnProperty(checkprop)) {

The variable checkprop you use here is different from checkProp in the parameters of the function because capitalization is important when it comes to variables.

Just match that checkprop variable to the one in your parameters of the function, and you will be good to go!

2 Likes

ReferenceError: checkprop is not defined

This always means the same. You are referencing an identifier that doesn’t exist. The two most common reasons are.

  • Typos.

  • Accessing the identifier in the wrong scope.

2 Likes

@marcusparsons and @lasjorg are both correct. Such errors are easy to make and sometimes looking at the error which displays in the console can make it easier to spot errors.
In this case:

ReferenceError: checkprop is not defined

Was displayed in the console because it couldn’t found the variable of checkprop defined. Not always the error is clear but sometimes this can be very helpful.
Your great that you did so well with only an issue of a little typo. I wasn’t so lucky and spent hours on this step :sweat_smile:.

1 Like

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