Struggling to Understanding Properties and Objects

Can anyone explain why you return obj[checkProp] and not checkProp[obj]? I’m struggling to understand what goes in the brackets and what goes outside of the brackets.

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

checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift");

Your browser information:

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

Challenge: Testing Objects for Properties

Link to the challenge:

Objects can contain multiple key/value pairs. ie const my_object = {gift: “pony”, pet: “kitten”, bed: “sleigh”}.

To reference the value for a given key using bracket notation, the syntax is: my_object[key] where the key is a string.

So in this scenario, my_object["gift"] will return "pony" . You could also use dot notation with (thanks @ilenia ) .

1 Like

if gift is not a variable containing the wanted value, then it must be my_object["gift"] or

You should use 3 backticks before and after your code.
Your code will look like the following.

function car(){


Objects and Properties

Hope it helps

1 Like

If you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

thanks! I updated my post so it didn’t confuse anyone

Sorry! Thanks for letting me know!

Thanks! I realized I was getting confused because I was mixing up terms. I didn’t understand what was meant by “property” and “object”.