Basic JavaScript - Testing Objects for Properties

You should try to explain it. You need to engage with the code - copying other people’s answers and explanations doesn’t do a ton to help you do similar tasks on your own.

hasOwnProperty is very useful. I can’t give you a trivial example - especially if you don’t understand accessing object properties via bracket notation.

You don’t seem to understand what checkProp is. Can you try to explain what you think it is?

So I think of it this way

The two parameters in the function are like this (object, value)

so like

const myObj = {
property: value?

something like that

You have it backwards. The arguments are the object and a property that the object might have.

Seeing the example here it gives, I understand.

const myObj = {
  top: "hat",
  bottom: "pants"
};

myObj.hasOwnProperty("top");
myObj.hasOwnProperty("middle");

But I just don’t know what to apply from that example.

I don’t understand what you mean by ‘what to apply from that example’. The example shows using hasOwnProperty and the solution requires hasOwnProperty.

The challenge gives you an example on the left, which is what I put above. I understand the example. I just don’t know how to apply that example to the problem we are supposed to solve.

How did you come up with this then if you didn’t understand how to use the example? Lucky random guess?

What wording in the problem hints that
obj[checkProp]
is needed

If the property is found, return that property’s value.

Ok. Hopefully there are more problems like this so I can get practice. I’ll move on for now lol. Thanks for your help.

1 Like

As the curriculum progresses, the challenges move away from ‘use this exact line of code’ and more towards ‘accomplish this thing with the syntax in previous challenges’.

This is the basic layout principal that you should follow to solve your problem

Given an object obj,
that has a property : value pair of checkProp : ”?”
Respectively

if the above condition renders true
→ return the value of checkProp
Or
“?” …In this case

//Note how to pull a value of a property in an object below

Object[property]

Hope this helps you understand better

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.