Thank you for your help!
It turns out, it has nothing to do with the block being collapsed. But your suggestion caused me to look yet again at the entire block to be sure it matched exactly the image in the badge instructions -- and then it finally jumped out at me: I was missing double quotes in the js block:
The error is exceptionally misleading. It has an arguably correct message (wrong input), but flashes the entirely incorrect block of code. That's really unfortunate.
But thanks again @sandcastlewizard for your help. It did the trick!