Error in this program

pls help me i cant solve this nd do pls help me with what I did wrong

var obj = {
   gift:"pony",
   pet:"kitten",
   bed:"sleigh"
 };

function checkObj(checkProp) {
 // Only change code below this line
if(obj.hasOwnProperty(checkProp) == 1)
{
 return obj[checkProp];
}else
{
 return "Change Me!";
}

 // Only change code above this line
}checkObj("gift");
   *

var obj = {
   gift:"pony",
   pet:"kitten",
   bed:"sleigh"
 };

function checkObj(checkProp) {
 // Only change code below this line
if(obj.hasOwnProperty(checkProp) == 1)
{
 return obj[checkProp];
}else
{
 return "Change Me!";
}

 // Only change code above this line
}checkObj("gift");
   **Your browser information:**

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

Challenge: Testing Objects for Properties

Link to the challenge:

Your code is a bit confusing but you actually dont need all of this.
All you actually need is -

return (obj.hasOwnProperty(checkProp)) ? obj[checkProp] : "Not Found"

If you insist on doing it your way, then correct all the errors in the code. Like extra { brackets , unwanted objects like

var obj = {
   gift:"pony",
   pet:"kitten",
   bed:"sleigh"
 };

This should be “Not Found” instead.

Remove the == 1 part.

And you forgot the obj parameter in your function.

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