Ok, just to be clear because this comment is ambiguous as to if you understand what I'm saying.
The comprehension in your article is not valid, you need to change one thing or the other for it to work.
> Dishes is an object of key value pairs
Yes, and you are getting the KEYS, not the VALUES. I doubt I need to say this, but per the spec KEYS are ipso facto strings.
At the point you do
plate.dirty
"plate" is a STRING, one of the key names in the dishes object.
See, here is the compiled code fresh from the compiler (with added comments):
var plate;
if (meal.status === 'done') {
for (plate in dishes) {
// plate is a STRING, plate.dirty will not exist
// you want dishes[plate].dirty
if (plate.dirty) wash(plate, brush, sink);
}
}
You're making the mistake of thinking CS will do the plate = dishes[ key ] part for you, but it won't...do it yourself or us "in" on an array.
You'll also note there are no sanity checks, so use with caution.
This is precisely what I mean when I talk about not knowing CS well enough. I mean this with all due respect and do not intend to dismiss you. You are clearly very bright and a good coder. Anyone will get tripped up in any language at first.
The point is I've used CS so much I breathe this stuff...I knew instantly that it was an invalid construct.... I'm simply saying (like any language) once you learn it well enough a lot of these sorts of issues fade into the background.
Maybe you don't think it's worth the effort to get to this point, and that would be fair enough. I just think it needs saying that some of the points you raise are related to being relatively new to CS.