I need a JavaScript code that would perform a function after a countdown of a value assigned to a variable | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

I need a JavaScript code that would perform a function after a countdown of a value assigned to a variable

Like var a = Number(document.getElementById('cD').value) Html *********************** <input type='text' id='cD' /> *********************** So that when I enter value 5, it counts down to 0 and performs the task I want it to. Thanks in advance..... šŸ¤˜šŸ¤˜šŸ¤˜

4th Oct 2018, 8:36 PM
Emmanuel
Emmanuel - avatar
1 Resposta
+ 1
function count_down(n, callback){ if(n >= 0) return callback() setTimeout(count_down(n - 1), 1000) console.log(n) } your_input_element.oninput = () => { count_down(Number(your_input_element.value), your_function) } I just have typed this so I don't know if it works, but you can try šŸ˜ƒ
4th Oct 2018, 9:00 PM
MatĆŗÅ” Semančƭk
MatĆŗÅ” Semančƭk - avatar