<h1>Testing Objects for Properties </h1>

sir,
I am not able to pass the test under the above curriculum. whenever I try to run the test I get the following .
// running tests

checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house")

should return

"Not Found"

.

checkObj({city: "Seattle"}, "district")

should return

"Not Found"

. // tests completed
my code is : `function checkObj(obj, checkProp) {
// Only change code below this line
var myobj={
gift: “pony”,
pet:“kitten”,
bed: “sleigh”
};
if (myobj.hasOwnProperty(checkProp))
{
return myobj[checkProp];}
else {
return “Not found”;
}

}

checkObj(“gift”);

// Only change code above this line`
in the checkObj(obj, checkProp) in line 1 obj is dimmed and am I required to change the ‘obj’ in line 1 to ‘myobj’? if I do so still I cannot pass the test.
I have tried all the codes given in the hints, yet no passing. As I am newbie , I request for exact code to start below line 1 to pass the test. thanks.

Hi!

  1. In your code you have written ‘found’ in lowercase and it should be ‘Found’ !
  2. In your code you have declared a new variable called ‘myobj’. That is not asked and superfluous! You should only use the variable ‘obj’ in the function.
  3. remove also the last instruction ‘checkObj(“gift”);’

That means:
Remove the whole declaration of ‘myobj’ from your code and and replace it in your ‘if’ and 'return ’ with ‘obj’

I have just done those changes and your code runs perfectly!

Try it and if you have further questions do not hesitate to ask them!

1 Like

thanks for guidance.
As suggested I changed my code to
function checkObj(obj, checkProp) { // Only change code below this line if (obj.hasOwnProperty(checkProp)){ return obj[checkProp]; } else { return " Not Found"; } }
when I run the test the following message is given:
// running tests checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house") should return "Not Found". checkObj({city: "Seattle"}, "district") should return "Not Found". // tests completed
the problem is that the test is not being passed. the same solution is given in the help video.
what and where I am missing , I fail to understand.
pl advise. thanks.

Hi!

I think it was only because there was a space at the beginning of
" Not Found". It should not be. But you already corrected it!

thanks . it passed after I removed the space before " Not Found".
so nice of you.

1 Like