Is there something I am missing here?

checkObj({pet: "kitten", bed: "sleigh"}, "gift") should return the string Not Found . Is a passing parameter I am failing to get my head around since there is a similar request requiring an opposite result. I am going to skip this test for now , any assistance is welcome.

  **Your code so far**

var myObj = {
gift: 'pony',
pet: 'kitten',
bed: 'sleigh',
city: 'Seattle'
};

function checkObj(obj, checkProp) {
if (myObj.hasOwnProperty(checkProp)) {
return myObj[checkProp]
} 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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36

Challenge: Testing Objects for Properties

Link to the challenge:

The description says:

Modify the function checkObj to test if an object passed to the function ( obj ) …

The object passed in, obj. You are using the global object myObj.

Hi @P.Mat3 !

A lot of people struggle with this challenge.
So it is completely normal to get stuck on this one.

You can go ahead and delete this.

You are not supposed to create your own object.
Your function should work for any object.
Not just one you created yourself.

Inside the function you want to use the obj parameter instead of myObj

The goal of the function is to check if obj has a property of checkProp and if so return the value
Otherwise return Not Found.

When we call the function, that is where we will use the object and test if the property exists.

Not here

Here is an example function call

checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift")

In this function call, we are checking this object {gift: "pony", pet: "kitten", bed: "sleigh"} to see if it has a property called "gift"

In this case,"gift" exists so we can return "pony"

Our function should work for hundreds of objects.
And hundreds of function calls.

You don’t want to hardcode hundreds of objects for this function.
That’s not practical.

Instead we are going to use the function parameters of obj and checkProp
Remember that parameters act as placeholders for the real values.
We use the real values when we make the function call.

Hope that helps!

2 Likes

I appreciate the detailed explanation. You helped a lot.