Testing Objects for Properties (What am I missing?)

Testing Objects for Properties (What am I missing?)
0

#1

Tell us what’s happening:

Your code so far


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

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




// Test your code by modifying these values
myObj("pony");

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties


#2

I have spend a lot of time trying to understand this… and I believe I understand the code but I am also confusing myself. We are using a condition to check if the object has a given property… does (checkProp) mean that we are checking the property of the variable and then if it has it’s own property return true? I kinda get it and kinda don’t - really just confused about (checkProp) party, which I know is the type of function being used


#3

Hey @ColonelForbin,
Your code is perfectly fine and it passes the tests for me.

You are calling the wrong function over here.
See if this helps.


#4

Thank you… that makes more sense now that I am looking at it. checkObj is using the function to check a property of the set of variable… right? Functions have been confusing for me but just gotta do more of them to get it