Basic JavaScript - Testing Objects for Properties fail

Tell us what’s happening:

Hello! I got stuck with testing objects code, pls need some help here.
It does not return the string Not Found .

Your code so far

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Safari/605.1.15

Challenge Information:

Basic JavaScript - Testing Objects for Properties

Hello!

The task teaches you to use the hasOwnProperty() prototype.

That is what needs to be the condition within the if statement brackets.

Let hasOwnPropery() check if the object has a property. A hint how to do this, the syntax, is in the example!

1 Like

Still can’t pass( what I do wrong here? :

function checkObj(obj, checkProp) {
// Only change code below this line

return obj.hasOwnProperty(checkProp);
}
if ({gift: “pony”, pet: “kitten”, bed: “sleigh”}) {
return obj[checkProp];
}
else {
return “Not Found”;
}
// Only change code above this line
}

Check my reply once again:

I can’t get into more detail because I’m moving close to spoiler territory already (which would get my posts deleted).

solved! thank you for help))

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