What's wrong with the code? (Testing Objects for Properties exercise)

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

It seems that there is some problem with the condition:

if (obj.hasOwnProperty(checkProp))

but what is it?
thanks

Hi, can you include a link to the original problem. Its very hard to help without all the information.
Although a quick obvious issue is that your if statement is missing parenthesis.

if (condition)
 {                                 /// YOU NEED THESE
    code to run;
}                                 /// YOU NEED THESE

You should use the bracket notation for accessing object properties that are function arguments/variables. Dot notation will not work.

1 Like

There is nothing wrong with not using curly braces for conditionals. To make typing faster and less DRY we can skip the curly braces. It is correct syntax.

You can refer to this article

1 Like

Thanks for this I didn’t know and it’s pretty fundamental!

1 Like