Testing Objects for Properties test

Tell us what’s happening:
The code is not running here in this editor.

Your code so far


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

function checkObj(obj, checkProp) {
 // Only change code below this line
if(myObj.hasOwnProperty(checkProp)){
   return myObj[checkProp];
 }
   return "Not Found";
}
checkObj(gift);


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0.

Challenge: Testing Objects for Properties

Link to the challenge:

I got the answer on my own. The Code should be

var myObj = {
   gift : "pony",
   pet : "kitten",
   bed : "sleigh",
   city: "Seattle",
};

function checkObj(obj, checkProp) {
  // Only change code below this line
if(myObj.hasOwnProperty(checkProp)){
    return myObj[checkProp];
  }
    return "Not Found";
 }
checkObj("gift");
checkObj("city");

no, it shouldn’t

you never use the function parameter obj, making the function not reusable

1 Like