Testing Objects for Properties.I am stuck here from several hours

Tell us what’s happening:
Hi campers! I don’t know what’s wrong with my code.I have tried to solve this problem by consulting several different posts but it still does not work.I am stuck here from several hours.Please guide me :confused:

  **Your code so far**

function checkObj(obj, checkProp) {
// Only change code below this line
var myList = {
"gift":"pony",
"pet": "kitten",
"bed": "sleigh",
"city": "Seattle"
};

if (myList.hasOwnProperty(checkProp)) {
return myList[checkProp];
} else {
return("Not Found");
};
};

// Only change code above this line



console.log(checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift"));
console.log(checkObj({pet: "kitten", bed: "sleigh"}, "gift"));
console.log(checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet"));
console.log(checkObj({city: "Seattle"}, "city"));
console.log(checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house"));
console.log(checkObj({city: "Seattle"}, "district"))
  **Your browser information:**

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

Challenge: Testing Objects for Properties

Link to the challenge:

1 Like

I have tried.It still not working @Excardical

Can you share your updated code with us?

You don’t need this part at all.

You don’t need to create your own object.

You just need the if else statement to pass the test using the correct parameter instead of myList.

I tried to fiqure out my mistake but could not found.Thank you so much @jwilkins.oboe :hugs:

1 Like

2021 update…

It works …

// Only change code below this line

var myObj ={

  gift:"pony",

  pet: "kitten",

  bed: "sleigh",

  city:"Seattle"

};

function checkObj(obj,checkProp) {

if(obj.hasOwnProperty(checkProp)){

  return obj[checkProp];

}else{

  return "Not Found"

}

}

  // Only change code above this line

  console.log(checkObj(myObj,"gift"));

  console.log(checkObj("house"));
1 Like

Hi @Hamatan !

Welcome to the forum!

I have added spoiler tags around your code since it is a full working answer.
In the future, please do not post full solutions but rather help guide the OP to the right answer through hints.

Also, you don’t need to create your own object here.

var myObj ={

  gift:"pony",

  pet: "kitten",

  bed: "sleigh",

  city:"Seattle"

};

The goal of the function is to test it with any object provided. So there is no need to create your own.
Hope that helps! :grinning: