I'm trying to set up a javascript that sequentially writes a phrase within my div, and after a few seconds it replaces the text with another pre-programmed one, I already tried to do with for, timer and still can not, instead of waiting the first message is written to write the second it simply writes both at the same time.
var div = document.getElementById('log');
var texto = ['Hoje está um lindo dia!','Hoje não está um lindo dia!','Hoje o dia estar horrivel'];
function escrever(str, el) {
var char = str.split('').reverse();
var typer = setInterval(function () {
if (!char.length) return clearInterval(typer);
var next = char.pop();
el.innerHTML += next;
}, 100);
}
setTimeout(escrever(texto[0], div),5000);
setTimeout(escrever(texto[1], div),5000);
<div id="log"></div>