I have a typewriter function as such:
var myArray = [
'sentence. another sentence.',
'this sentence. yet another sentence.',
];
var rand = myArray[Math.floor(Math.random() * myArray.length)];
var i = 0;
var speed = 55;
function typeWriter() {
if (i < rand.length) {
document.getElementById("question").innerHTML += rand.charAt(i);
i++;
setTimeout(typeWriter, speed);
}
}
typeWriter();
<div id="question"></div>
How can I have the typewriter function speed change to say, 80ms, if the character it's currently typing is a period or comma, then return to 55ms when it's typing normal letters? This would help me to imitate the rhythm of speech with the typing function and improve readability. Thanks for your help.