I recommend deciding on the machine state with the attached class. Button texts (and texts in general) tend to change over time. Using something like
if (btn.className === 'on') and also changing the class feels more stable.
I hope that helps,
Thanks for your feedback