Basic JavaScript - Testing Objects for Properties

Tell us what’s happening:
Describe your issue in detail here.
I’m not sure about the requirements and how to do this exercise, can anyone help? result comes out at “false” sometimes, “not found” sometimes. at this moment, no matter what is put in console.log () returns false.
the original is function checkObj(obj, checkProp), but the request is
" Modify the function checkObj to test if an object passed to the function (obj) contains a specific property (checkProp). If the property is found, return that property’s value. If not, return "Not Found"."
I think this mean i have to use .hasOwnProperty to check if ‘checkProp’ is available within obj or not, not inside ‘checkObj’. Does that mean it is just a simple check on the properties and return certain answers like ‘Not found’ and the values instead of ‘true’ or ‘false’. It would be be so helpful if i can have a complete code with some explanations.
Your code so far

function checkObj(obj) {
// Only change code below this line
obj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
city: "Seattle"
if (obj.hasOwnProperty("")==true){return obj} else {return "Not found"}
// Only change code above this line
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

Hey! Welcome to the freeCodeCamp’s community forums.

You’re only supposed to modify the code below this line,

but it looks like you changed the function definition too.
This particular challenge expects you to modify the give function such that whenever it is called with an object and a property like this.

checkObj(someObj, someProperty);

it will return true or false depending on whether the property exists on that particular element or not.

Just restart this challenge and try attempting it. if you need further help with this, Let me know! :smile:

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