Estoy tratando de entender cómo funcionan las variables en javascript. Aquí está mi código:
textarea.addEventListener('keyup', (e) => { singleChoices.innerHTML = textarea.value .split(',') .filter((eintrag) => { return eintrag.trim() !== '' }) .map((choice) => { return `<span class="choice">${choice.trim()}</span>\n` }) .join('') if (e.code === 'Enter') { textarea.value = '' const choice = getRandomChoice() const repeat = setInterval(() => { blinkOn(choice) const verzoegerung = setTimeout(() => { blinkOff(choice) }, 30) }, 30) const stopRepeat = setTimeout(() => { clearInterval(repeat) blinkOn(choice) }, 2000) } }) function getRandomChoice() { const choices = document.querySelectorAll('.single-choice .choice') let randomIndex = Math.floor(Math.random() * choices.length) return (choice = choices[randomIndex]) }Estoy tratando de crear un efecto de parpadeo. BlinkOn agrega una clase con un nuevo color a un lapso aleatorio (llamado elección), blinkOff está eliminando esta clase nuevamente.
Mi pregunta: Después de dos segundos, quiero mantener el último índice aleatorio y volver a llamar a blinkOn ON en ese índice. Breve: necesito usar el mismo valor del índice aleatorio en la parte stopRepeat. ¿Cómo tengo que definir las variables? ¡En este momento no lo entendí!