It is necessary for the method to work for a certain time, for example, to output a word in the textarea for 5 seconds, which can be used for this?
1 answer
let output = document.getElementById('output'), interval = setInterval(() => { output.textContent += 'слово '; }, 1000); setTimeout(() => { clearInterval(interval); }, 5000); <textarea id="output" style="width: 300px;"></textarea> Or even easier:
let interval, seconds = 0, output = document.getElementById('output'); interval = setInterval(() => { if (++seconds < 6) output.textContent += 'слово '; else clearInterval(interval); }, 1000); <textarea id="output" style="width: 300px;"></textarea> |
setTimeout()perfect. - yar85