Basic JavaScript: Testing Objects for Properties: help please!

Tell us what’s happening:
Getting an ‘X’ still on the requirement: checkObj({pet: "kitten", bed: "sleigh"}, "gift") should return "Not Found" .

I’m not sure what I should do to meet this requirement? All others are fine.

Your code so far


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";

}


// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36.

Challenge: Testing Objects for Properties

Link to the challenge:

you have a function parameter you are not using, you are instead always testing the same global
object meaning your function is not reusable

How do you test the object passed in?

if you notice the object there does not have gift property, you are testing an object that has it

I got it. Thanks! The variable I used myObj was wrong. It needed to be “obj” to coordinate with the parameter from the original function.

var obj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
city: "Seattle"}
function checkObj(obj, checkProp) {
  // Only change code below this line
if (obj.hasOwnProperty(checkProp)){
return obj[checkProp];
} else {
return "Not Found";

}
}

why do you still have the global object, why have you changed its name?

Good question! I saw all of the properties (?) (pony, etc) and thought I might need to include it when I was stuck.

You are right, it doesn’t need that.

the object being tested is anyway the one passed in

if you use obj inside the function it will use function parameter, and as it has found something it will not look outside of the function for its value
(with myObj the function didn’t have a variable named such so it looked outside to find it)

Yes, I see that now…erg!

Thanks for your help!