Help for Understanding 'Testing Objects for Properties'

Hi everyone. Does the value in the checkObj(“pet”); replace ‘checkProp’?

You’re going to need to give more context than that.

Can I post my answer to the challenge, ‘Testing Objects for Properties’ so I can show what I’m asking?

Please do.

When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

markdown_Forums

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

function checkObj(checkProp) {
  // Your Code Here
  var PC = myObj[checkProp];
  return PC || "Not Found";
  
}

// Test your code by modifying these values
checkObj("pet");

Putting ‘checkprop’ into ‘function checkObj(checkProp)’ passes ‘checkProp’ into the function. Then, does “pet” in checkObj(“pet”) replace ‘checkProp’? Does “pet” = checkProp? Am I right?

1 Like

That’s right checkProp is just a parameter for checkObj function. Whenever you call the function, you’re supposed to pass a parameter. Of course, there are function which don’t require any attributes.

Hello, use Object.prototype.hasOwnProperty()

checkProp is a variable. Specifically it’s an argument variable.

No, but checkProp = “pet”.

Thanks guys.:slightly_smiling_face: