This question makes no sense

Tell us what’s happening:

Your code so far



// Only change code below this line
var myObj = {
 gift: "pony",
 pet: "kitten",
 bed: "sleigh",
 city: "Seattle"
};

function checkObj(checkProp) {
if (myObj.hasOwnProperty(checkProp)) {
  return myObj[checkProp];
} else {
  return "Not Found"
}
// Only change code above this line
}

console.log(checkObj("city"))

Your browser information:

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

Challenge: Testing Objects for Properties

Link to the challenge:

Hi @anderioan!

Welcome to the forum!

Your task is to check if obj has a property of checkProp. Not myobj

myobj was just the example for the lesson. It is not supposed to be used in the answer for this challenge though.

So I would reset the lesson.
Your logic here was correct but just apply it to the obj not myobj

thanks! its just that there is nothing in the prompt on making the list of objects that are required to complete the problem like the city, bed, etc. stuff

1 Like

You don’t have to create an object at the top.

The idea is to write a function and test it with a variety of different objects.

Everytime we call the function checkObj(obj, checkProp) we can pass through any object and check if the property exists.

1 Like

then how does the console know that city will mean seattle or bed will mean sleigh, etc?

I think part of the confusion is that there are tests written by the fcc staff that you don’t see.

For this challenge, you need to write a reusable function so when the tests are being called behind the scenes they run through each of these function calls.

Test cases
Function call 1:checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift")
Functions call 2: checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet")
etc.

its just that changing the name to obj does nothing either.

Your function is missing some information

function checkObj( ???, checkProp)

On the left it tells you what it calls for the last one example:
checkObj({pet: "kitten", bed: "sleigh"}, "gift")

English:
Look in (pet: “kitten”, bed: “sleigh”), and give me what is contained in gift. Which doesn’t exist because it wasn’t included in that search in this case. Even though you do have it in the list.

If it called ({gift: “pony”, pet: “kitten”, bed: “sleigh”}, “gift”) then you would get pony as gift is included.

1 Like

That’s why I suggested you reset the lesson and use your logic behind creating a if else statement but using the parameter obj instead of myobj.

In your original post you had altered code you were not supposed to.

It would help to see the updated code.

it worked! Thanks a bundle!

1 Like