Testing Objects for Properties - JS

[Describe your issue in detail here.

  **Your code so far**](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties)

I just don’t understand this one, please instruct me how to fix this!

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

function checkObj(checkProp) {
// Your Code Here
return myObj[checkProp];
else if(myObj.hasOwnProperty(checkProp) !== true){
return “Not Found”;
return “Change Me!”;
// 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/99.0.4844.74 Safari/537.36 Edg/99.0.1150.55

Challenge: Testing Objects for Properties

Link to the challenge:

You were not asked to write the function the way you have written it.

Do not use code you find on the forum. If you absolutely want solution code use the official solution code found at the top of the “Get a hint” page (Get help > Get a hint).


You put this function inside of the original function. That’s strange.

function checkObj(obj, checkProp)

This function has the argument obj. You need to use this argument instead of hard-coding myObj.

I’d reset this challenge to clear out the confusing parts you’ve added. You have the pieces of the right logic in there, but with parts of an old solution mixed in.

Our challenges change from time to time. I recommend against copying old solutions you find because the don’t always match the current version of the challenge.

Also, getting the check marks isn’t really the important part of these challenges. The important part is practicing figuring out how to write code for a new problem. There’s always plenty of time to look at other people’s answers after you solve the problem yourself for the first time.

1 Like

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