I need help with__ https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

function checkObj(obj, checkProp) {
// Only change code below this line
if checkObj(obj){
  gift: "pony"
  pet: "kitten"
  house: "Not Found"
  city: "Seattle"
  district: "Not Found"
}
return "Change Me!";
// Only change code above this line
}
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36

Challenge: Testing Objects for Properties

Link to the challenge:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.


Can you describe what you think this code does?

Thank you for getting back to me. I am trying to figure this part out from the module: " 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" ."

You ought to modify line 3 so that if obj has a property called checkProp(as entered in the function call) it should return the value of that property else return “Not Found”.
Use .hasOwnProperty to do the checking and add an else line.
I hope I helped make your life easier.

Hello @morifingk just as @JeremyLT as said you need to be quite specific in what the problem is for others to be able to help.

  • Here’s your first mistake :

This is an if statement and should only contain conditions inside the parenthesis (). You seem to be treating this as a function checkObj().

  • You would want to have your object stored in a variable outside of the function because you would be passing that object as an argument to the function.
  • Each time you set a property: value for an object you should always separate them with a comma the last property is considered optional.
  • Lastly in your conditional statement I believe you would need to return a certain value if it is found in the object that is being passed to the function. Check the examples given and then you can come back here if you’re still stuck.

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