import Timeout = NodeJS.Timeout; let intervalTime = 150; let dataIndex = 0; let stringPosition = 0; let printTask: Timeout; let terminal:HTMLElement; let historyContainer:HTMLElement; let promptContainer:HTMLElement; function writeOut() { // @ts-ignore let currentData: { [key: string]: string } = data[dataIndex]; let currentText: string = currentData["strings"]; promptContainer.innerText = promptContainer.innerText + currentText.charAt(stringPosition); stringPosition++; if(stringPosition > currentText.length){ stringPosition = 0 dataIndex++; historyContainer.innerHTML = historyContainer.innerHTML + "$ " + promptContainer.innerHTML + "
" + currentData["output"] + "

"; promptContainer.innerHTML = ""; clearInterval(printTask); // @ts-ignore if(dataIndex < data.length){ // @ts-ignore setTimeout(startNewTask, data[dataIndex - 1].postDelay); } } } function startNewTask() { terminal = document.getElementsByClassName("terminal")[0]; historyContainer = terminal.getElementsByClassName("history")[0]; promptContainer = terminal.getElementsByClassName("prompt")[0]; printTask = setInterval(writeOut, intervalTime); }