I need some help...Testing objects for properties

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

  **Your code so far**

var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
function checkObj(obj, checkProp) {
// Only change code below this line
return obj[checkProp];
else if(myObj.hasOwnProperty(checkProp) !== true){
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/92.0.4515.131 Safari/537.36

Challenge: Testing Objects for Properties

Link to the challenge:

Remember, all the checks you do inside of the function should be on the object passed into the function.

Hi @mwangieric !

Welcome to the forum!

You are not supposed to create your own object.
You can delete this

You are supposed to use the obj function parameter.
Not myobj.

As for the function itself, I don’t think you need that else if statement.

When you think about it either the property exists or it doesn’t.

I would just use a if else statement and get rid of the else if.

1 Like

Thank you for getting back to me,

Do you mind explaining further?

Thank you for your feedback😊

I think @jwilkins.oboe pretty much explained it as well as I ever could. If you are still having problems please explain exactly what you don’t understand.


Here obj is an argument to your function

So you should use obj inside of your function instead of referencing the global object myObj you found somewhere.

You want your function to work for any object rather than just one specific object, and you do that by using the function argument.

1 Like

It sounds like the confusion is coming from the example code here

var myObj = {
  top: "hat",
  bottom: "pants"

A lot of people will create their own objects because that is what the example did.

But you are not supposed to do that for the challenge.

Your job is to create a reusable function that works for ANY object.
Not just one that we hardcoded ourselves.

That’s why in the line here

You need to reference obj not myObj.

That way when we call the function, we can pass in any object.

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