Basic JavaScript - Testing Objects for Properties

Hi Everyone,

I have the following requirements for the completion of this task:

  • Passed: checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift") should return the string pony.

  • Passed: checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet") should return the string kitten.

  • Passed: checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house") should return the string Not Found.

  • Passed: checkObj({city: "Seattle"}, "city") should return the string Seattle.

  • Passed: checkObj({city: "Seattle"}, "district") should return the string Not Found.

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

Now, is it even possible to make gift return and not return at the same time?

If the

checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift") should return the string pony.

task is completed, then the

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

task is bound to fail, isn’t it?

Thank you in advance for your help.

function checkObj(obj, checkProp) {
// Only change code below this line
const myObject = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh",
  city: "Seattle",
}
 if (myObject.hasOwnProperty(checkProp)) {
   return myObject[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; rv:102.0) Gecko/20100101 Firefox/102.0

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

You don’t want to create the object myObject inside of the function. The object you are checking is the object passed into the function via the obj parameter. All of your checks in the function should be done with obj.

Oh, I see. Well, it is very late here, probably I should go get some sleep and get back to learning tomorrow! :smiley: Thank you a lot for your help.

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