Bug or wrong? please help

Tell us what’s happening:
Describe your issue in detail here.
is still get this: checkObj({pet: “kitten”, bed: “sleigh”}, “gift”) should return the string Not Found.
How do i fix my code


.
       **Your code so far**


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

  
 return "Change Me!";
 // Only change code above this line
}


   **Your browser information:**

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

Challenge: Testing Objects for Properties

Link to the challenge:

You are creating your own object, myObj. Don’t do that - you should be using the one that is passed in as a parameter, obj. That way the function is more flexible and the tests can test it with different objects.

When I fix that, your code passes for me.

1 Like

Thanks for the quick respond… Really appreciate it. do you mean like this:
// because i still get the same error

function checkObj(obj, checkProp) {

// Only change code below this line

var Obj = {

gift: “pony”,

pet: “kitten”,

bed: “sleigh”,

city: “Seattle”,

};

if(Obj.hasOwnProperty(checkProp)){

return Obj[checkProp];

}

else return “Not Found”;{

return “Change Me!”;

}

// Only change code above this line

}

No, I’m saying this:

var Obj = {
  gift: “pony”,
  pet: “kitten”,
  bed: “sleigh”,
  city: “Seattle”,
};

Don’t do that. You were passed a parameter:

function checkObj(obj, checkProp) {

That first parameter, obj, is the object you should be using, the one that is being passed in.

1 Like

got it!! thanks for the tip :ok_hand:t5:

1 Like

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