A JavaScript implementation of a Finite State Machine