JSFiddle - React, Tailwind, and code Playground
JavaScript
const printMessage = (target, message, frequency) => {
console.log('COUCOU')
message.forEach((line, lineIndex) => {
const previousCharacters = message.slice(0, lineIndex).join(' ').length
line.split('').forEach((character, charIndex) => {
setTimeout(() => {
target.innerHTML = `${target.innerHTML}${character}${charIndex === line.length - 1 ? '<br/>' : ''}`
}, (previousCharacters + charIndex) * frequency)
})
})
}
printMessage(document.getElementById('target'), [
'Hello World!',
'How are you ?'
], 100)