I don't know how to solve, I have tried many times

Tell us what’s happening:
I don’t understand why it’s not working.

   **Your code so far**


const object= {
 gift: "pony", 
 pet: "kitten", 
 bed: "sleigh",
 city: "Seattle",
}
console.log(checkObj["pet"]);
function checkObj(checkProp){
var check = object.hasOwnProperty[checkProp];
return (check==true? object[checkProp]: "Not Found");
 // Only change code above this line
}
   **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.3 Safari/605.1.15

Challenge: Testing Objects for Properties

Link to the challenge:

You changed the function signature.

function checkObj(obj, checkProp) {

The tests have no way of knowing that you completely changed the function signature, so its impossible for the test suite to use your function.


So, lets start there. You need to fix the function signature of your function to have two arguments, obj and checkProp.

did that still not working, also why it has two parameters when we only need to check one value?

What is your new code?

It has two parameters because you have 1) the object to check and 2) the property you are looking for.

so we will pass two parameters when we call the function?

Yes. The test will always call your function with two parameters.

it says obj is undefined.

Where? Please share your updated code.

const object= {
  gift: "pony", 
  pet: "kitten", 
  bed: "sleigh",
  city: "Seattle",
}
console.log(checkObj["pet"]);
function checkObj(obj, checkProp){
var check = object.hasOwnProperty[checkProp];
return (check==true? object[checkProp]: "Not Found");
  // Only change code above this line
}

Lets back up and get rid of this. You should not use a global variable like this. The function should only know about obj.

function checkObj(obj, checkProp){

var check = object.hasOwnProperty[checkProp];

return (check==true? object[checkProp]: "Not Found");

// Only change code above this line

}

console.log(checkObj["pet"]);

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

But you are now ignoring obj and still trying to use object. That can’t be good.

its says ReferenceError: Can’t find variable: obj

function checkObj(obj, checkProp){
var check = obj.hasOwnProperty[checkProp];
return (check==true? obj[checkProp]: "Not Found");
  // Only change code above this line
}

console.log(obj["pet"]);

Right, because of this line.

function logThis(myArgument) {
  console.log(myArgument);
}

console.log(logThis("here is a test");
console.log(myArgument); // Can this line work?
1 Like

no , output will be “here is a test”.

But what happens with the last line? myArgument is not in scope for that line, right?

1 Like

yes, so I need to declare obj?

If you want to use it outside of the function. But there is no reason to do that.

Why do you want this line?

1 Like

Sorry, its by mistake is was calling the function which is checkObj([“pet”]);
here is my current code,

function checkObj(obj, checkProp){
var check = obj.hasOwnProperty[checkProp];
return (check==true? obj[checkProp]: "Not Found");
  // Only change code above this line
}
  checkObj(["pet"]);
  const obj= {
  gift: "pony", 
  pet: "kitten", 
  bed: "sleigh"
}

Thanks for your help :slight_smile: