Testing objects for property

good evening, is there something i’m doing wrong. please help.

Your code so far


function checkObj(obj, checkProp) {
// Only change code below this line
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(obj, checkProp) {
if(obj.hasOwnProperty(checkProp)) {
  return obj[checkProp];
} else {
  return "Not Found";
}
}


// Only change code above this line
}

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0.

Challenge: Testing Objects for Properties

Link to the challenge:

@mitanshi please help

  1. myObj does not need to be declared as objects are passed in the backend to the function checkObj. So various obj for testing the code is automatically passed by the freecodecamp website.
  2. The problem with the code is that function is declared one inside another.
function checkObj(obj, checkProp) {
function checkObj(obj, checkProp) {
return statements
}
}

so the first function checkObj at line 1 is not returning anything. See the below code for reference.

function checkObj(obj, checkProp) {
  // Only change code below this line
  if(obj.hasOwnProperty(checkProp)){
    //console.log(obj[checkProp])
   return obj[checkProp] 
  }
  
  else
  return "Not Found"
  // Only change code above this line
}

I hope I could explain clearly :sweat_smile:

finally passed this. i did not notice. thank you so much.