This code would pass my console.log tests but wouldn’t be accepted as answer. Unsure why but had to check hint and implement a == true
test to pass.
function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty(checkProp)) {
return myObj[checkProp];
}
else {
return "Not found";
}
}
The string you return when the property does not exist must match the required on exactly.
unsure I follow. This is the solution:
function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty(checkProp) == true) {
return myObj[checkProp];
}
else {
return "Not Found"
}
}
The only difference here is that I haven’t used == true
on hasOwnProperty(checkProp) == true
Why is this an issue?
That is not the only difference. When you do not find the property in the object, what do you return?
Thanks for reverting.
When I do not find the property in the object, I return
Typos are the enemy. Happy coding!
1 Like
FYI, the == true
part is never needed when something already returns true or false. Try this out instead:
if (myObj.hasOwnProperty(checkProp))
1 Like