Text 'guesser' / tumbler like animation I made a tumbler thingy...
Do you see possible bugs in the code or any improvements I could do?



var text = "0000 ASCII (Listeni/ˈæski/ ass-kee), abbreviated from American Standard Code for Information Interchange,[1] is a character-encoding scheme (the IANA prefers the name US-ASCII[2]). ASCII codes represent text in computers, communications equipment, and other devices that use text. Most modern character-encoding schemes are based on ASCII, though they support many additional characters. ASCII was the most common character encoding on the World Wide Web until December 2007, when it was surpassed by UTF-8, which includes ASCII as a subset.[3][4][5]";

// Returns a random integer between min and max.
function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

function tumbler(text) {
  var length = text.length;
  var tumbleText = "";

  function tumble() {
    var code, i, newTumbleText = "",
      rand;

    // Test if we're done.
    if (text === tumbleText) {
      return document.body.style.color = "white";
    }

    for (i = 0; i &lt; length; i++) {
      // Compare the two chars.
      if (text[i] !== tumbleText[i]) {
        code = text.charCodeAt(i);
        rand = getRandomInt(code - 10 &lt; 0 ? 0 : code - 10, code + 10);
        newTumbleText += String.fromCodePoint(rand);
      } else {
        newTumbleText += text[i];
      }
    }

    tumbleText = newTumbleText;
    document.body.textContent = tumbleText;
    window.setTimeout(tumble, 60);
  }

  tumble();
}

tumbler(text);
body {
  background: black;
  color: lime;
  font-family: Courier, monospace;
}
Pretty fun little bit of code. Very neatly written as well. Only thing I would suggest would be to use .charAt(x) instead of using array indexers for your strings when you're comparing characters. Not a big deal but will improve compatibility among browsers and is a bit easier to read IMHO.

// Compare the two chars.
if (text.charAt(i) !== tumbleText.charAt(i))


Good stackoverflow post covers it in more detail here.