const string = "Добро Пожаловать SlivCours",
printer = (str, elem) => {
let _str = str.split``;
const t = setInterval(() => (_str.length) ?
elem.textContent += _str.shift() :
clearInterval(t) , 100);
}
printer(string,document.getElementById('test'));
function printer(str, elem) {
return new Promise((resolve) => {
const chars = str.split('');
const t = setInterval(() => {
if (chars.length) {
elem.textContent = elem.textContent + chars[0];
chars.shift();
} else {
resolve();
clearInterval(t);
}
}, 100);
});
}
printer('Добро Пожаловать ', document.getElementById('test1')).then(() => {
printer('SlivCours', document.getElementById('test2'));
});