I can't get my code to work

Tell us what’s happening:
Describe your issue in detail here.
Kindly check if this code I wrote is right. I can’t see the error

   **Your code so far**

function checkObj(obj, checkProp) {
 // Only change code below this line
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty(checkProp)) {
return myObj[checkProp];
} else {
return "Not Found";
}

}

// Test your code by modifying these values
checkObj("gift");
 // 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/94.0.4606.81 Safari/537.36

Challenge: Testing Objects for Properties

Link to the challenge:

What is this object? It is not part of the instructions. You need to use the function argument obj.

I just changed it. Something is still wrong

What is your new code?

function checkObj(obj, checkProp) {

  // Only change code below this line

var obj = {

gift: "pony",

pet: "kitten",

bed: "sleigh"

};

function checkObj(checkProp) {

// Your Code Here

if (myObj.hasOwnProperty(checkProp)) {

return myObj[checkProp];

} else {

return "Not Found";

}

}

}

You are ignoring the value of obj that is being passed in. You need to completely delete this hard-coded object. The instructions do not tell you to hard code an object.

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

I unfortunately still don’t understand what you expect from me but hoping someone else explains better
I have been on this code for 45mins

Completely delete these five lines.

Delete this random extra function definition too.

There is no myObj. You must use the obj.


It looks like you perhaps copy-pasted an old answer without understanding it.

1 Like

wow! I have been suffering myself, it has worked.

I actually was writing my code and had to check “hint” and thought I was doing it wrong. Thank you.

This is the sort of thing that happens when you copy answers you find on the hints thread. Posts after the first one often have answers to old versions of the challenges.