Basic JavaScript - Testing Objects for Properties

Testing Object Property
I do not pass the code, because the question was not clear enough.

function checkObj(obj, checkProp) {
// Only change code below this line
const checkObj = {
‘obj’: ‘red’,
‘checkProp’: ‘{gift: “pony”, pet: “kitten”, bed: “sleigh”}’
}
checkObj.hasOwnProperty({gift: “pony”, pet: “kitten”, bed: “sleigh”}, “gift”);

// Only change code above this line
}

function checkObj(obj, checkProp) {
  // Only change code below this line
  const checkObj = {
  'obj': 'red',
  'checkProp': '{gift: "pony", pet: "kitten", bed: "sleigh"}'
  }
   checkObj.hasOwnProperty({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift");

  // 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/108.0.0.0 Safari/537.36 OPR/94.0.0.0

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

The instructions were

Modify the function checkObj to test if an object passed to the function (obj ) contains a specific property (checkProp ). If the property is found, return that property’s value. If not, return "Not Found" .

Which part did you find not clear enough so we can clarify it?

The idea of this function is that it should take any object passed to it via the obj parameter and check if the property (checkProp) exists within it.

You shouldn’t put an object inside your function.

All you need to do is write a conditional (if) statement which checks if the object (obj) has the property (checkProp) and either return the property’s value, or ‘Not Found’ if it doesn’t exist.

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