Basic JavaScript - Testing Objects for Properties

Help! I don’t know how to access the checkObj(obj) function or maybe I’m not writing it right. In the return part of my code, what I’m trying to output is that whatever checkProp is, I want it to go to obj, check what the value is and return it. I’ve been stuck on this for days.

  **Your code so far**
function checkObj(obj, checkProp) {
// Only change code below this line
if (checkObj.hasOwnProperty(checkProp)){
return checkProp.obj;
} else {
return "Not Found";
// Only change code above this line
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

There is no checkObj. The only two variables you have are obj and checkProp.

I’m not sure what you think this syntax does. Can you explain?

Okay so, the first question we need to ask is: what does the function checkObj do?

At the moment it seems to be taking in two parameters something called obj and something called checkProp.

In your post you said this:

whatever checkProp is, I want it to go to obj, check what the value is and return it.

So you are saying that checkProp is something related to obj right? In that case, do you think you should ask obj the question? Right now your code says

if (checkObj.hasOwnProperty(checkProp))

So you are asking “checkObj” not obj.
Does it make sense to ask checkObj this question? (Who would know the most about obj but obj?)

It’s for accessing the Object property

Accessing which object’s property?

Hmm you’re very right. Lemme adjust it

1 Like

Wow it just worked! Thank you so much!

1 Like

Anything checkprop might be. But thanks though. Ive already seen my mistake

I have one more question though. Why is it that dot notation wont work for the return, only bracket

Dot notation only works with the exact, literal property name. It doesn’t work with a variable holding a property name.

Really smart, thanks a bunch

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