Typewriter

by NullDev

HTML

<span id="game_output"></span>

JavaScript

const sleep = ms => new Promise((res) => setTimeout(res, ms));

const typeWrite = async function(input_text, speed = 70){
    for (const char of input_text){
        document.getElementById("game_output").innerHTML += char;
        await sleep(speed);
    }
};

const newGame = function(){
    typeWrite("A man approaches you...");
}

newGame();