How to Test Objects for Properties

Tell us what’s happening:
I cannot seem to get it done.


// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
// Your Code Here
if(myObj.hasOwnProperty(checkProp)){
return myObj[checkProp];
}
else if(myObj.hasOwnProperty(checkProp) !== true){
return "Not Found";
}
else{
return "Change Me!";
}
}

// Test your code by modifying these values
checkObj("gift");

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36.

Challenge: Testing Objects for Properties

Link to the challenge:

You changed the function signature:

function checkObj(obj, checkProp) {

Copy-pasting old solutions sometimes results in completely breaking the code.

I’d reset your challenge to restore the correct function signature.

You need to check if obj has the property checkProp. You should not reference the global variable myObj.

Welcome there,

I’ve changed your thread title to describe your problem more clearly. Descriptive titles, such as “Why does my function return undefined?”, are more likely to elicit helpful responses than generic titles, such as “Help please”.

1 Like

Thanks, could you also close it. I solved my bugs thanks to fcc’s YouTube playlists

Regards,
Aryan Singh
Network Analyst and Designer

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