I’m only getting one error saying “gift” should return “Not Found”.
When I delete the property “gift” from the obj object I get an error saying that “gift” should return “pony”. It seems like it’s asking for 2 different answers for the same property and I can’t figure out how to get past this error. Thanks!
I can get each one of these tests to pass but I cannot get both to pass at the same time:
checkObj({pet: "kitten", bed: "sleigh"}, "gift") should return the string Not Found .
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift") should return the string pony .
**Your code so far**
function checkObj(obj, checkProp) {
// Only change code below this line
var obj = {
"gift": "pony",
"pet": "kitten",
"bed": "sleigh",
"city": "Seattle"
}
if (obj.hasOwnProperty(checkProp)) {
return obj[checkProp];
} else {
return "Not Found";
}
// Only change code above this line
}
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15
I believe it will create a local object and store those values so when someone looks up the property the data is in the obj object. Is this data already stored in the question behind the scenes or something?
You are correct, it creates the obj variable which is local to the function. Notice that it has the same name as the obj parameter for the function. So by creating the local obj you “shadow” the obj being passed into the function.
Which obj are you supposed to be checking properties on?
We can look to the instructions for the answer:
“Modify the function checkObj to test if an object passed to the function ( obj )* contains a specific property”
OHHHHHHHHH I see. The function itself is creating the object with all of the stuff contained in the first argument. The next argument is the property to be checked. My statement checks if obj contains a certain property and if so returns the value! If not then Not Found. Do I have a good grasp on it?