+ 2

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:37 PM
Emmanuel
Emmanuel - avatar
7 odpowiedzi
+ 5
Kehinde Emmanuel, Hope this helps👍 function CountDown() { var val = $("#input").val(), count = new Number(val), fin = 0; setI = setInterval(function Count(){ count-=1; $("#box1").html("<br>"+count); if (count==fin){ clearInterval(setI); return; console.log("Countdown Finished!"); } },1000); } Code Snippet:: https://code.sololearn.com/WlDyo8Vki987/?ref=app
4th Oct 2018, 9:07 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
+ 3
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 it 😃
4th Oct 2018, 9:03 PM
Matúš Semančík
Matúš Semančík - avatar
+ 3
Kehinde Emmanuel, You're welcome, anytime👍 Lol🌴😂😂
4th Oct 2018, 9:32 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
+ 2
I've not tried it... But thanks bro
4th Oct 2018, 9:07 PM
Emmanuel
Emmanuel - avatar
+ 2
🌴Vincent Berger🌴 Thanks a lot man. Can you help me with a coconut, I can see you are surrounded by coconut trees😂😂😂 Thanks once again man
4th Oct 2018, 9:26 PM
Emmanuel
Emmanuel - avatar
+ 2
amit Thanks for checking on me bro, I really appreciate that, but I'm requesting for javascript code not python.
8th Oct 2018, 6:18 AM
Emmanuel
Emmanuel - avatar
- 1
# Import the modules import sys import random ans = True while ans: question = raw_input("Ask the magic 8 ball a question: (press enter to quit) ") answers = random.randint(1,8) if question == "": sys.exit() elif answers == 1: print "It is certain" elif answers == 2: print "Outlook good" elif answers == 3: print "You may rely on it" elif answers == 4: print "Ask again later" elif answers == 5: print "Concentrate and ask again" elif answers == 6: print "Reply hazy, try again" elif answers == 7: print "My reply is no" elif answers == 8: print "My sources say no"
7th Oct 2018, 2:26 PM
amit
amit - avatar