Technical error with Testing Objects for Properties

Tell us what’s happening:
The question called Testing Objects for Properties is loading up with an error that reads- “(both) obj + checkProp is declared but its value is never read.” It also looks different from the video tutorial in that it’s missing the set-up portion where the object is declared along with the properties and their values. I tried resetting the answer multiple times; I’m not having any luck.

Thanks

Your code so far


function checkObj(obj, checkProp) {
// Only change code below this line
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/80.0.3987.163 Safari/537.36.

Challenge: Testing Objects for Properties

Link to the challenge:

Forget about the video. Pretend you didn’t see it. It references an old version of this challenge which doesn’t exist anymore.

You have two arguments being passed into the checkObj function: obj and checkProp. Those are the only things you need to pass this challenge.

Still unable to pass. What am I doing wrong?

function checkObj(obj, checkProp) {
  // Only change code below this line
  if (checkObj.hasOwnProperty(checkProp)) {
    return checkObj[checkProp];
  } else {
    return "Not Found"
  }
  // Only change code above this line
}

checkObj is the name of the function, so you wouldn’t be checking that for an object property. You want to check the object passed into the function for the property. You have two arguments passed into the function but you are currently only using one of them. Use both of them.

1 Like

change checkObj for obj

Sometimes it’s nice to let someone figure it out on their own :slight_smile:

2 Likes

haha thanks, I’m sure I will value the mistery once I figure it out lol for now it’s just eating at my brain lol

can I use a AND statement for both of them? would that work? lol

You’ll have to give me an example of what you mean.

1 Like

so is it correct to assume that in a set of arguments, one is an object and the other is property? I’m just trying to make sense of your comment

I meant one is a property and the other is a value… I’m sorry my brain is fried over this lol

For this particular function, yes, the first one is an object (hence named obj) and the second one is the property you want to check for in the object (hence named checkProp). But that is not a rule in general for functions. This function could have very easily had checkProp as the first argument and obj as the second.

1 Like

I tried:

function checkObj(obj, checkProp) {

  // Only change code below this line

if (obj.hasOwnProperty(checkProp)) {

  return checkObj.checkProp;

} else {

  return "Not Found";

}

  // Only change code above this line

}

What exactly are you trying to return in this function? If the property you are checking for (stored in the checkProp variable) does not exist in the object then you return ‘Not Found’. But if it does exist in the object then you want to return the value stored in that property in the object.

So how do you get the value of a property in the object? We know the name of the object is obj and we know the name of the property we are checking for is stored in checkProp. What notation can we use to get the value?

1 Like

the brackets? [ ] - these?

Exactly. Now put it all together in the first return statment.

Nothing, my friend.

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
}

even tried with quotes obj[“checkProp”]

You have it correct except that you have a silly typo. I don’t want to ruin the fun and tell you exactly where it is but I will remind you that JS is very case sensitive.

1 Like

WOW.

and i almost gave up LOL