Basic JavaScript - Testing Objects for Properties

Tell us what’s happening:
Describe your issue in detail here.
Hi lovely comunity,

I am not understanding this one. I tried based on some forum replies but I still do not seem to be able to pass this test. Can someone explain me how to solve and also explain why it is so?

I am feeling a little lost now.

Thank you in advance.
Your code so far

function checkObj(obj, checkProp) {
  // Only change code below this line
if (obj[checkObj]){
   return obj[checkObj];
}
else {
  return "Not Found";
}
   // Only change code above this line
} console.log(checkObj({gift: "pony", pet: "kitten", bed: "sleigh"})

Your browser information:

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

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

He challenge talks about

hasOwnProperty

So you probably need to use it

1 Like

What is the ‘checkObj’ and where it is defined in the code?
You should check if argument ‘obj’ has its own property (argument ‘checkProp’ in the function). If it has that property then the function call should return its value:

For example, If I have an object ‘myObj’:

const myObj = {gift: "pony", pet: "kitten", bed: "sleigh"};

After the function call and print output in the console, we should get:

console.log(checkObj(myObj, "gift"));

Console:
pony

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