Testing Objects for properties?

so firstly i’d say for a beginner this question was way too confusing i get what it was try to say but like i didn’t even know that you could pass the method .hasOwnProperty within the argument or parameter or whatever its called.

Now everything pass except the last part “gift” should return Not Found. i already put in the return statement and everything else pass why is it not passing for the last one??

  **Your code so far**

function checkObj(obj, checkProp) {
// Only change code below this line
  gift: "pony",
  pet: "kitten",
  bed: "sleigh",
  city: "Seattle"
  return obj[checkProp];
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/88.0.4324.150 Safari/537.36.

Challenge: Testing Objects for Properties

Link to the challenge:

You should not be redefining the obj inside of your function.

wait it worked?? wait what how come? i didn’t see object being created why then would it pass the test that require it to acess gifts value or pets value?? So a obj as within a function’s parameter is the same as creating a object?

Yeah, when you pass in an object with as the function parameter, it is used by the function.

Oh so the questions assume that the values for the object eg . gift: “pony” etc are already created outside of the function so we just have to make a function to find out the properties of the said obj…is that correct?

Exactly. We need our functions to execute the same logic for many different objects, and we do that my passing those objects in as function arguments.

1 Like

it says

checkObj({pet: "kitten", bed: "sleigh"}, "gift") should return "Not Found" .

in the function call an object is passed in as first argument, {pet: "kitten", bed: "sleigh"}, and a string as second argument, "gift"

the object already exists outside the function