Testing Objects for Properties Question

Testing Objects for Properties Question
0.0 0

#1

Hi guys!

I have a problem with that challenge:
Instructions
Modify the function checkObj to test myObj for checkProp. If the property is found, return that property’s value. If not, return “Not Found”.

My code:


// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  var myObject = myObj.hasOwnProperty(checkProp);
  if(myObject == true){
    return checkProp;
  }else{
  return "Not Found!";}
}

// Test your code by modifying these values
checkObj("gift");

Everything is working right, but I’m not going forward. Can someone explain why it’s happening?

Link to the challenge:


#2

There are two things that you have to change:

  1. If the property is not found, you are returning “Not Found!”, but it should be without an exclamation mark.
  2. If the property is found, you are returning the property name (‘checkProp’), but you should return the value that that property holds. E.g. instead of gift return pony.

#3

Thank you so much for your help! Now I’m in the next challenge. :slight_smile: