JSFiddle - React, Tailwind, and code Playground

HTML

<h1>State Machine Tranzitions</h1>

<div id='container'></div>

CSS

div {
    border:1px solid gray;
    font: small Verdana;
}

JavaScript

var div = document.getElementById('container');

function log(text) {
    div.appendChild(document.createTextNode(text));
    div.appendChild(document.createElement('br'));
}


// The old state and the current states of the machine
var ost, st = 0;

function process() {
    switch (ost = st) {
        case 0:
            st = 1;
            break;
        case 1:
            st = 2;
            break;
        case 2:
            st = 0;
            break;
        default:
            st = 0;
    }
    if (ost !== st) {
        log(ost + ' to ' + st);
        console.log(ost, st);
    }
};

setInterval(process, 1000);