Challenge [Testing Objects for Properties]
User Agent is: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0
.
Please describe how to reproduce this issue, and include links to screenshots if possible.
My code:```javascript
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh" };
function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty("checkProp")=== true);
{return myObj[checkProp];}
return "Not Found" ; }
// Test your code by modifying these values
checkObj("house");
I'm using a firefox browser and cannot get a screen-shot to paste - sorry. My issue is the final 'return "Not Found"; ' statement in this exercise will not execute when the condition is false. I checked the format of this exercise with one from a previous exercise (Chaining If Else Statements), and it is the same basic format once you comment out the extra if-else statements there. I did not find any other solutions in Git Hub or elsewhere online. I did notice some people used an 'else' in front of ' return "Not Found" ; ', but when I attempt it, I get an error, otherwise, the editor does not show any other errors for my code.
You have a semicolon after the if
statement.
It should be
if(myObj.hasOwnProperty("checkProp")=== true)
You have written
if (myObj.hasOwnProperty("checkProp")=== true);
In future, if you have questions like this, please ask in the channel, before filing an issue. For now, please close this issue.
Sorry, but Issues are not for code problems. Please ask for help in Help Chat.
Thanks and Happy Coding!
Vulgarities and insults will not be tolerated -- @ltegman
Why the brackets in ?
return myObj[checkProp];
OK, this is another example of not getting enough information from the sample code. Nowhere in there is the suggestion that an if/return/else statement should be used....
good!
You can even omit === true from the conditional statement since the only output which Boolean datatype produce is either true or false :
if (myObj.hasOwnProperty("checkProp"));
{return myObj[checkProp];}
return "Not Found" ; }
this is the working code
removed solution by mod
I'm not sure where else to put this piece of .02, but honestly, the chat room is NOT helpful. For people who are really trying hard to put in the effort that it takes to learn to code (for me, with ZERO tech background), it seems like there would be a forum available to help. This feels like the 50 millionth time I've tried finding help through the forums and it's really offputting to just see moderators telling people to use the (useless and unhelpful) chat room. It's frustrating learning to code as it is, and this insistence on using a form of "help" that isn't helpful is making it so much worse.
A clean solution can be :
removed solution by mod
why should we use brackets
return myObj[checkProp];
@Apollovishwas to access myObj Properties ...
removed solution by mod
Dude the no solution rule is really dumb, and you shouldn't enforce it.
if(myObj.hasOwnProperty(checkProp))
return myObj[checkProp];
else
return "Not Found";
more simple
Why is this not working?
function checkObj(checkProp) {
// Your Code Here
return (myObj.hasOwnProperty(checkProp)===true) ? myObj[checkProp] : "Not found";
}
Most helpful comment
OK, this is another example of not getting enough information from the sample code. Nowhere in there is the suggestion that an if/return/else statement should be used....