Basic JavaScript - Testing Objects for Properties

Tell us what’s happening:
Describe your issue in detail here.
I really don’t understand what im doing, i don’t know how to do the Not Found response, thinking i was following the past lessons i believe what i was doing is correct, but checking forums there are things i have to do outside of what this lesson teaches you? I honestly don’t know where i am standing either
Your code so far

function checkObj(obj, checkProp) {
  // Only change code below this line
  const checkObj = { 
    gift: "pony",
    pet: "kitten",
    bed: "sleight",
    city: "Seattle",
  };

return checkObj[checkProp];
  // 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/109.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

You shouldn’t create this object. You aren’t using the function argument obj.

so should i delete “const checkObj” and just put obj?

You should delete the checkObj, yes.

Allright so now it looks like this

function checkObj(obj, checkProp) {
  // Only change code below this line
  var obj = { 
    gift: "pony",
    pet: "kitten",
    bed: "sleight",
    city: "Seattle"
  };
if (obj.hasOwnProperty(checkProp)) {
    return obj[checkProp];
  } else {
    return "Not Found";
  }
  // Only change code above this line
}

Now, the only test im missing is the last one:

checkObj({pet: "kitten", bed: "sleigh"}, "gift") should return the string Not Foundwhich returns: " checkObj({pet: “kitten”, bed: “sleigh”}, “gift”) should return the string Not Found."

What am i missing?

Don’t rename this. Totally and utterly delete it.

obj and checkProp are the only two variables for you. Create zero variables. Change zero variables.

This part is good.

Passed it, but i completely don’t understand how i passed the tests if i didn’t declare what it asked (example: gift: “pony” and such), i am at a complete loss

You aren’t supposed to declare the obj. It isn’t the job of a function to create the arguments. It’s the job of a function to use the arguments.

1 Like

Thanks a lot! Now i understand the reason of that lesson :smiley:

1 Like

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