updated js example to use statemachines