Testing Object for Properties Exercise (2020)

Tell us what’s happening:
Hi guys, I was having problems completing this exercise.

I figured that if I added the property city: “Seatle” on top I could complete it.

If intended cool, if not then I have spotted this issue for future students


Here is my code

Your code so far

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

function checkObj(obj, checkProp) {
 // Only change code below this line
    if (myObj.hasOwnProperty(checkProp)) {
  return myObj[checkProp];
 else {
 return "Not Found";}

 // Only change code above this line

checkObj(myObj, "gift");

Your browser information:

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

Challenge: Testing Objects for Properties

Link to the challenge:

Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.

the function is defined with two parameters, you are not using both of them.

Hint: Forget about myObj completely. It is just there to show you how the function would be invoked. It is not necessary for solving this challenge.

Besides, an object is passed into the function as the first parameter obj. That is the object you want to be checking in the function.

I am very new to JS.

Could you please elaborate as to how should I use both of them?

Thank you!

FYI - The myObj variable was left over from a previous version of this challenge. I have created a pull request to remove it from the challenge seed code inorder to prevent confusion.

I’m not sure I understand your question. Do you mean how do you use both of the function parameters in the body of the function? You are already using one of them (checkProp):

if (myObj.hasOwnProperty(checkProp)) {
  return myObj[checkProp];

checkProp was passed into the function and represents the property name you want to check for in the object.

The issue with your code is that you are using the myObj object to make this check instead of the object passed into the function. So you just need to update your code to use the name of the object passed into the function (the first parameter) to make this check.

1 Like