-
Notifications
You must be signed in to change notification settings - Fork 0
/
count.js
63 lines (55 loc) · 1.64 KB
/
count.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var countInterval;
var current = document.querySelector('.current');
var next = document.querySelector('.next');
function startCounter(){
var number = parseInt(document.getElementById("number").value);
if(isNaN(number)){
alert("Please Enter A number");
clearInterval(countInterval);
return;
}
if(number < 1 || number > 99999){
alert("range Out of Bounds");
clearInterval(countInterval);
return;
}
var currentNos = document.querySelectorAll(".counter .current");
var nextNos = document.querySelectorAll(".counter .next");
var count = 0;
resetNumbers(currentNos,nextNos,5);
clearInterval(countInterval);
countInterval = setInterval(function(){
if(count==number){
clearInterval(countInterval);
alert("Counter has Stopped");
return;
}
increaseCount(currentNos,nextNos,4);
count++;
},1000);
}
function resetNumbers(currentNos,nextNos,end){
for(var i=0;i<end;i++){
currentNos[i].innerText = 0;
nextNos[i].innerText = 1;
}
}
function increaseCount(currentNos,nextNos,index){
let current = currentNos[index-1];
let next = nextNos[index];
if(current.innerText == 9){
increaseCount(currentNos,nextNos,index-1);
}
next.classList.add("animate");
setTimeout(function(){
current.innerText = next.innerText;
next.classList.remove('animate');
next.innerText = parseInt(next.innerText) + 1;
if(next.innerText > 9){
next.innerText = 0;
}
},500);
}
// function animate(){
// next.classList.add('animate');
// }