Challenge Testing Objects for Properties has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.
My code:
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
if(myObj.hasOwnProperty(checkProp)){
return myObj[checkProp];
}
return "Not Found";
}
// Test your code by modifying these values
checkObj("gift");
_edited by mod_
Issue Description
Clarity issue on this problem - User allowed to use dot operator to access value. however using dot operator(obj.prop NOT obj."prop" as given in the paramater) in this instance creates undefined value - out of scope of this exercise
Hi @mszaf! Thank you for reporting this issue.
It took me a bit to understand what you were saying, so to save others the same struggle, here's what I believe this is about. This challenge does not mention how to return the value when it is present. Campers could try to return the value as return myObj.checkProp rather than return myObj[checkProp]
The previous challenge talks about the correct method, so I feel this is probably fine as it is.
What do you all think?
@systimotic
Thanks for looking into this.
My issue was a matter of the purpose of the test being to check for understanding in regards to the .hasOwnProperty method versus the small difference in dot accessing and bracket accessing an object.
Secondly, how the test is written - only parameters surrounded in quotes are passed to the user's method.
Therefore using any sort of dot access isn't possible as : varName."someProp" isn't valid.
Test is simple enough, yet, if you make the mistake of using the dot operator in an access in this test, time is wasted attempting to trace for an error in the new material : .hasOwnProperty() and not a simple syntax error that is somewhat abstracted due to a variable being passed to the funtion.
Hopefully I've clarified what I had noticed,
-Morgan
I had this issue as well & looked for the problem in my code within the given content, I didn't think about the bracket/dot till seeing this thread.
Hi @mszaf. Sorry for the late reply!
I could see how this is confusing to you.
@drumz77 @mszaf Would a note saying "Remember to use bracket notation to access the property" or something similar help you? My concern is that it might confuse users, that they will think they need to use it in the place of hasOwnProperty. I'm not sure what the best way to handle this is, but I agree that it could be improved.
@systimotic
I think what would be most helpful for users woukd be a test to check if they're using an incorrect object access method. Then they're given an explanation as to why they can't use their implementation if they use the wrong method.
Is more of a thing of if you have information written in the introduction some may not read it. If someone makes a mistake and is presented with the exact reason it's not working they're more likely to retain that information.
@mszaf That's a good idea, I think that could work!
Hi, I have a question whit this challenge..
why dont work the following code?, it isnt the same of the mszaf but whitout brackets...? the dot dont works?
thank you
`var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty(checkProp)==true){;
return myObj.checkProp;
}else{
return "Not Found";
}
}
// Test your code by modifying these values
checkObj("gift");`
Hi @mszaf @rdsandovalm
my code is working find for all the values.
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty(checkProp)){
return myObj[checkProp];
} else{
return "Not Found";
}
}
// Test your code by modifying these values
checkObj("pet");
Its really weird that its showing error for using .operator instead of [] while accessing the values of myObj. I searched online and everywhere it saying we can access property of a object in two ways:-