function checkObj(obj, checkProp) {
// Only change code below this line
var obj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
… test if an object passed to the function ( obj )…
So, you are not supposed to create your own object, but use the one passed into the function:
function checkObj(obj, checkProp) {
Your second problem is here:
if (obj.hasOwnProperty("checkProp")){
You are passing that method a string literal, so it is checking if that specific string exists, in other words, you are checking if obj has a property specifically called “checkProp”. But you want to check the string that is held in a variable by that name.
When I fix those two things, your code passes for me.