Testing objects for properties --need help

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

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

 else{
 return "Not Found";
 }

 // Only change code above this line
}

i am getting this eror
// running tests
checkObj({pet: "kitten", bed: "sleigh"}, "gift") should return the string Not Found.
// tests completed

unable to understand. Please help


   **Your browser information:**

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

Challenge: Testing Objects for Properties

Link to the challenge:

your code is correct but you have declared variable result above the comment where it instructs you to only change code below this line

yes, this was a second trial after i was not getting results in the below code

function checkObj(obj, checkProp) {

// Only change code below this line
obj={
“gift”: “pony”,
“pet”: “kitten”,
“bed” : “sleigh”,
“city” : “Seattle”,
};
if (obj.hasOwnProperty(checkProp)){
return obj[checkProp];

}

else{
return “Not Found”;
}

// Only change code above this line
}
this code still gives the same error

sorry I did not notice it earlier, you are not supposed to create obj of your own, when function checkObj is called the obj is created and given as argument

oooh i get it
Thanks a lot
got success !!

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