Help for Understanding 'Testing Objects for Properties'

Help for Understanding 'Testing Objects for Properties'
0

#1

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


#2

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


#3

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


#4

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.


#5
// 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?


#6

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.


#7

Hello, use Object.prototype.hasOwnProperty()


#8

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

No, but checkProp = “pet”.


#9

Thanks guys.:slightly_smiling_face: