Testing For Object Properties

Tell us what’s happening:
The Last test won’t pass –

checkObj({pet: "kitten", bed: "sleigh"}, "gift")

should return the string

Not Found

I’m not sure what is wrong with this current setup?

  **Your code so far**

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

Challenge: Testing Objects for Properties

Link to the challenge:

Hints:
1, obj.hasOwnProperty(prop) will return true if the property is present or false otherwise;
2, use bracket notation to access property value e.g obj[“property”]
insum:

if(obj.hasOwnProperty(prop)) {
   return  use bracket notation to access property value;
}else{
return "Not Found"
}

If obj and checkProp is equal to “gift”

Thank you that gave me a hint to solve it!

Thank you for pointing out the (checkProp == "gift). I hadn’t realized it was only checking the one part of it.

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