+ 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 ответ
+ 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