Check for objects property

Hello FreeCodeCamper s
I’m trying to find a property inside my object with the hasOwnProperty() method, but when I pass the argument to the function, although I have declared
the object earlier to the function but its return Not Found

var obj = {
    age : "29",

function checkObj(obj, checkProp) {
  // Only change code below this line
   if (obj.hasOwnProperty(checkProp)){
       return obj[checkProp];

  return "Not Found";
  // Only change code above this line
console.log(checkObj( "age"))

im sure that i have a mistake somewhere any Hint will be appreciated

Your function takes two arguments. Calling it with only one argument won’t give you what you want.


Remember, you’ve defined two variables named obj.

First, you’ve got that global one you’ve defined, but second, look closely at that function. It takes two parameters and defines local variables for them: obj and checkProp.

With this, you’ve set your first parameter (obj) to “age”, and the second (checkProp) to undefined.

Is that your intent?


Thanks a lot, @snowmonkey finally i found it :sweat_smile:

console.log(checkObj( obj,"age"))```
1 Like