Im stuck and need help

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

  **Your code so far**

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

var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

if (myObj.hasOwnProperty(checkProp)) {
  return obj[checkProp];
} else {
  return "Not Found";
}
}






checkObj("gift");





// Only change code above this line

  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36

Challenge: Testing Objects for Properties

Link to the challenge:

  1. The object is passed as an argument to the function. Do not create the object inside the function yourself.

Shouldn’t be inside the function:

var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
  1. The parameter myObj is not the same identifier as obj you are using both. You should be using the myObj parameter which is what gets the object passed to it.

The wrong identifier, should be myObj

return obj[checkProp];

Thank man appreciate it

1 Like

So should the myobj variable me outside the function

You can’t use a parameter outside the function, it is scoped to the function. A parameter is just a local variable that you can pass values to using arguments when calling the function.

// firstName is the parameter
function logName(firstName) {
  console.log(firstName); // John
}

// 'John' is the argument
logName('John');

console.log(firstName); // reference error

If you wanted to use the value inside a parameter outside the function you have to either assign it to an outer scoped variable or return it out of the function. None of which is relevant to this challenge.


  1. Remove the object you added

  2. Change obj to myObj for the return on the line I showed.