Testing objects for properties troubles

what’s happening:
heyy
I’ve been working on this problem and have been able to provide 3 different solutions to be able to get all check, except the last one.

*checkObj({pet: “kitten”, bed: “sleigh”}, “gift”) should return the string Not Found .

is it requiring me to set up a “case” basis? ive done that and still same occurs.

any help is super appreciated!

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

checkObj("");

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36

Challenge: Testing Objects for Properties

Link to the challenge:

Hi @rsmith90 !

You are not supposed to create your own object.

This is incorrect.

You want to write a function that works for ANY object.

Not just one that you hardcoded yourself.

Hope that helps!

ive also tried without adding var’s but it x’s all

You need to delete the whole object.

Not just the var keyword.

removed whole object and ran checkObj({pet: “kitten”, bed: “sleigh”}, “gift”) and passed
*sighs in relief
thank you for your help!

1 Like

Hi @rsmith90 how are you, the prob is that you have defined the var obj inside the function so it has a local scope meaning, it cannot be accessed outside the function, and additionally you haven’t passed the correct function arguments ( checkObj("") ) and lastly the function parameter obj has been defined as a variable, my suggestion would be… Removing the obj variable and inputting the correct arguments in the function call => i.e

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

checkObj(object,"pet");

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