Why isn't my code working?

I am stuck at the “Testing Objects for Properties”
exercise and I am not entirely sure what’s wrong with it.

.hasOwnProperty() should return a boolean, and obj.checkProp a string right? What I am missing here ? I already tried to put the value of obj.checkProp into a variable and messing with the objects themselves. Nothing works D:

My code so far:

function checkObj(obj, checkProp) {
// Only change code below this line
  return obj.checkProp;
  return "Not Found";
// Only change code above this line

checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift");
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet");
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house");
checkObj({city: "Seattle"}, "city");
checkObj({city: "Seattle"}, "district");
checkObj({pet: "kitten", bed: "sleigh"}, "gift");
  **Your browser information:**

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

Challenge: Testing Objects for Properties

Link to the challenge:

Only if obj has a property with the literal name “checkProp”. Remember that dot notation only works with property names. If you are using a variable you need to use bracket notation.


Oh, thank you very much!

It’s working now! Ty very much :’)

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