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
  function checkObj(obj, checkProp) {
  if (obj.hasOwnProperty(checkProp)) {
    return obj[checkProp];
  } else {
    return "Not Found";
  }
}
  return "Change Me!";
  // 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/105.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

First of all, please ask a question. If you dropped off your car at the mechanic and refused to tell him the problem you were having, that would be rude.

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

Why do you wrap the function in itself?

1 Like

I,m sorry about that, and thanks for the correction,. but Kelvin, i did a copy and paste on my work their, i have been trying to understand it before i move to the next challenge , pls could you help with the explanation how that work… I was able to understand the example given from the challenge, but not my test result.

OK, what are specifically are you not understanding? There are a couple of things going on there. If I were to write the body of that function in pseudo code, it might look like:

if the value of checkProp is a property of obj
  return the value stored in property checkProp of object obj
else
  return "Not Found"

Which part of that are which specific syntax isn’t clear?

1 Like

seen, thanks for the details kevin.

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