Basic JavaScript - Testing Objects for Properties

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

function checkObj(obj, checkProp) {
  // Only change code below this line
  return checkProp.hasOwnProperty(obj);

  
  // Only change code above this line
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

hi everyone!

please am getting more confused as my code can’t pass. Can anyone give me more light here?

my code:

function checkObj(obj, checkProp) {
  // Only change code below this line
  return checkProp.hasOwnProperty(obj);

Have a look at the example in the challenge and compare it to your code - what is the hasOwnProperty applied to?

You should have some kind of if-else logic to return property's value or Not Found

honestly speaking am lost here totally. Don’t know what to anymore here.

Am getting frustrated…I need more explanation, please

It is normal to feel so in self-learning path. I would grab a coffee/ tea or a biscuit, or even take a nap.

Btw, have you took a look the Get Help → Get a Hint ?. I learnt a lot from there.

1 Like

Did you solve this? Your parameters are back to front in your return statement.

function checkObj(obj, checkProp) {
  // Only change code below this line
  return checkProp.hasOwnProperty(obj);

Also, this function would only return true or false, where you are supposed to return the property’s value (if it exists).
However, this challenge can be solved with a single return statement, using the logical OR operator…

I just did it correctly.

if (obj.hasOwnProperty(checkProp)) {
    return obj[checkProp];
  } else {
    return "Not Found";
  }
1 Like

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