Basic JavaScript - Testing Objects for Properties

function checkObj(obj, checkProp) {
// Only change code below this line
return “Change Me!”;
// Only change code above this line
}

Modify the function checkObj to test if an object passed to the function (obj ) contains a specific property (checkProp ). If the property is found, return that property’s value. If not, return "Not Found" .

I could not find the answers to the questions. can you help?

First of all, please always provide a link to the challenge - we aren’t psychic. :wink:

Or, use the Get Help -> Ask for Help button in the future - it does it all for you.

Next, please show us what you have tried. Or explain what you don’t understand. We don’t want to just give you the answer.

1 Like

first you need to check if the object passed to the function has specific property (checkProp). You can use obj.hasOwnProperty(checkProp), if its true return obj[checkProp] and return “Not Found” if its false.

Have you tried a code analysis tool? For example AppRefactoring

How would that be even remotely helpful?

I think there will be something like return obj[checkProp] ? obj[checkProp] : "Not found".

Please do not try to give solution code.

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