<h1>testing object for properties<h1>

my code won't run.


Kindly help point out where the error is



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

// Only change code above this line
}
console.log(checkObj("gift"));
  **Your browser information:**

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

Challenge: Testing Objects for Properties

Link to the challenge:

You have 2 issues here.

  1. If the key is found in the object, you’re supposed to return the value. Your code currently returns checkProp, which is the key, not the value.

  2. This one is just specific to the test, but you’re supposed to return “Not Found”, you’re returning “Not found”.

1 Like

I totally understand the second point, but the first still has me confused.

kindly expatiate

Lets say “obj” is:

{gift: "pony", pet: "kitten", bed: "sleigh"}

If “checkProp” were equal to “gift”, then as “gift” is a key found in this object, your code should return the value of that key, which in this case would be “pony”.
If “checkProp” were equal to “house”, it should return “Not Found”, because the object doesn’t contain that key.

2 Likes