Cant Get Solved >> Only One Step

Code working fine but the step below can not be covered :confused:

How can I clear following statement?:

  • checkObj({pet: "kitten", bed: "sleigh"}, "gift") should return the string Not Found .

Your code so far


function checkObj(obj, checkProp) {
 // Only change code below this line

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

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

Challenge: Testing Objects for Properties

Link to the challenge:

In the function, you are not using the obj parameter.

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

For this to work, use

if(checkObj.hasOwnProperty(checkProp)){   // Use obj instead of checkObj here

For simplicity, it is better to create the checkObj outside the function body, as a global variable and then pass checkObjas first parameter to the function.

You are the one who save my day :slight_smile: Thank you so much ! and greetings…

1 Like

There is no reason to create an object. The requirements of the function are that an object is passed in as an argument (called obj) and you need to check that object.

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