Basic JavaScript - Testing Objects for Properties

Could someone please help me with testing the objects for properties:
I don’t know how to do it.

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

Challenge: Basic JavaScript - Testing Objects for Properties

Do you see a problem here?

the curly bracket is after else rather than before?

and two return “found” needs to be removed

1 Like

first, fix the correct quantity of curly brackets, remember to open and close all code blocks. (i would start using indentation to help see code blocks).
then ask yourself what the code will do when it runs, specifically the part hbar1st highlighted.

You are also missing one } so make sure you have matching opening and closing curly braces

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