+ 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..... 🤘🤘🤘
7 ответов
+ 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
+ 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 😃
+ 3
Kehinde Emmanuel,
You're welcome, anytime👍
Lol🌴😂😂
+ 2
I've not tried it... But thanks bro
+ 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
- 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"