Basic JavaScript - Testing Objects for Properties

Tell us what’s happening:
Describe your issue in detail here.
I know I am missing something simple but I cannot figure out what for the life of me. If someone can please help I would really appreciate it

  **Your code so far**
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

  **Your browser information:**

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

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

This is the problematic line. I believe you should switch to using square bracket notation instead of dot notation in this case to access the actual value.

I had it using but that gave me the same problem

I’d have to see your code to comment. But the reason the dot doesn’t work here is because checkProp is a variable, not an actual property in the object.

I’m sure why but it worked this time? Thank you for responding though

1 Like

Sorry I meant I tried using the square brackets and it worked. I tried that before I used the dot notation so I’m not sure why it worked this time? Unless there was an object that was two words and I needed to use it and/or maybe just had something else wrong like a missing bracket before? Who knows, but thanks again. That was driving me mad

1 Like

You’ll probably run into this again and if you watch for it, you may even notice yourself doing something wrong next time (and then the mystery will be solved). We invariably make the same mistakes multiple times before we learn from them.

1 Like

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