Testing Objects for Properties-1

Testing Objects for Properties-1
0.0 0

#1

Tell us what’s happening:
please help me I am stuck here and cannot find what is wrong with it.

Your code so far


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

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

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

Your browser information:

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

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


#2

First of all you’re returning a string here:

“myObj.checkProp”

So the output is not evaluated ( the function will return "myObj.checkProp"everytime it founds an existent prop)

It will not work even if you take out the quotes though: that’s because you’re using a variable to retrieve the result. so you might use the bracket notations ^^


#3

Hi Akagra007,

  1. Don’t return myObj.checkProp as a string.
  2. myObj("gift"); should be checkObj("gift")
  3. This one too. function myObj(checkProp) should be function checkObj(checkProp)
  4. Make necessary changes to those affected by renaming.

Note: 2 and 3 aren’t spoilers as they are part of the initial code.

Happy coding!