I written the following code that displays each item of an array using a random timer delay.
const letters = ['H', 'e', 'l', 'l','o'];
const typeLetters = _ => {
letters.forEach((letter) => {
let ranNum = Math.ceil(Math.random() * 1000);
setTimeout(function(ranNum) {
lettersCon.textContent += letter;
}, ranNum * 1);
})
}
The problem I've got is the array items aren't being displayed in order, should display Hello. I believe this is due to how the eventloop works.
How can I use a random timer delay whilst keeping the output in order.