-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
60 lines (56 loc) · 1.34 KB
/
script.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
var mini = document.getElementById('minisec');
var min = document.getElementById('min');
var sec = document.getElementById('sec');
var seconds = 0;
var minutes = 0;
var miniseconds = 0;
var start = document.getElementById('start');
var stop = document.getElementById('stop');
var reset = document.getElementById('reset');
var interval;
function startTimer(){
miniseconds++;
if(miniseconds < 10){
mini.innerHTML = "0" + miniseconds;
}
if(miniseconds >= 10 && miniseconds < 100){
mini.innerHTML = miniseconds;
}
if(miniseconds > 99){
miniseconds = 0;
mini.innerHTML = "00";
seconds++;
}
if(seconds < 10){
sec.innerHTML = "0" + seconds;
}
if(seconds >= 10 && seconds < 60){
sec.innerHTML = seconds;
}
if(seconds > 59){
seconds = 0;
sec.innerHTML = "00";
minutes++;
}
if(minutes < 10){
min.innerHTML = "0" + minutes;
}
if(minutes >= 10 && minutes < 60){
min.innerHTML = minutes;
}
}
start.onclick = function(){
interval = setInterval(startTimer);
};
stop.onclick = function(){
clearInterval(interval);
};
reset.onclick = function(){
clearInterval(interval);
seconds = 0;
minutes = 0;
miniseconds = 0;
min.innerHTML = "00";
mini.innerHTML = "00";
sec.innerHTML = "00";
};