--- id: 567af2437cbaa8c51670a16c title: Testing Objects for Properties challengeType: 1 --- ## Description
Sometimes it is useful to check if the property of a given object exists or not. We can use the .hasOwnProperty(propname) method of objects to determine if that object has the given property name. .hasOwnProperty() returns true or false if the property is found or not. Example
var myObj = {
  top: "hat",
  bottom: "pants"
};
myObj.hasOwnProperty("top"); // true
myObj.hasOwnProperty("middle"); // false
## 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".
## Tests
```yml tests: - text: checkObj("gift") should return "pony". testString: assert(checkObj("gift") === "pony", 'checkObj("gift") should return "pony".'); - text: checkObj("pet") should return "kitten". testString: assert(checkObj("pet") === "kitten", 'checkObj("pet") should return "kitten".'); - text: checkObj("house") should return "Not Found". testString: assert(checkObj("house") === "Not Found", 'checkObj("house") should return "Not Found".'); ```
## Challenge Seed
```js // Setup var myObj = { gift: "pony", pet: "kitten", bed: "sleigh" }; function checkObj(checkProp) { // Your Code Here return "Change Me!"; } // Test your code by modifying these values checkObj("gift"); ```
## Solution
```js var myObj = { gift: "pony", pet: "kitten", bed: "sleigh" }; function checkObj(checkProp) { if(myObj.hasOwnProperty(checkProp)) { return myObj[checkProp]; } else { return "Not Found"; } } ```