Why this code is note working

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

function checkObj(obj, checkProp) {
// Only change code below this line
var myObj = {
gift: 'pony',
pet: "kitten",
bed: 'sleigh',
city: "Seattle"

};
if (myObj.hasOwnProperty(checkProp)) {
return myObj[checkProp];
} else {
return 'Not Found';
}

// Only change code above this lin
}
checkObj("gift");
  **Your browser information:**

User Agent is: Mozilla/5.0 (Linux; Android 10; Nokia 3.1 Plus) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36.

Challenge: Testing Objects for Properties

Link to the challenge:

I’ll try to give you some hints:

Why is var myObj in your function?
What’s the value of obj and checkProp inside the function checkObj? (use console.log() )
What do you pass to the function with checkObj("gift") ?

It looks like you don’t really understand the use of functions, so I would recommend to read more about them.

use

console.log(obj);
console.log(checkProp);

inside the function checkObj to see the value in the console window.

The way it is called now

checkObj("gift");

the parameter obj is “gift” and the parameter checkProp is empty.
obj should be an object on which you perform the .hasOwnPropertry(checkProp)

You should remove your object

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

and where you used myObj change it to obj

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.