-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (53 loc) · 1.49 KB
/
app.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
window.onload = function () {
var seconds = 00;
var miliSec = 00;
var minitues = 00;
var appendMiliSec = document.getElementById("miliSec");
var appendSeconds = document.getElementById("seconds");
var appendMinitues = document.getElementById("minitues");
var buttonStart = document.getElementById("button-start");
var buttonStop = document.getElementById("button-stop");
var buttonReset = document.getElementById("button-reset");
var Interval;
buttonStart.onclick = function () {
clearInterval(Interval);
Interval = setInterval(startTimer, 10);
};
buttonStop.onclick = function () {
clearInterval(Interval);
};
buttonReset.onclick = function () {
clearInterval(Interval);
miliSec = "00";
seconds = "00";
minitues = "00";
appendMiliSec.innerHTML = miliSec;
appendSeconds.innerHTML = seconds;
appendMinitues.innerHTML = minitues;
};
function startTimer() {
miliSec++;
if (miliSec <= 9) {
appendMiliSec.innerHTML = "0" + miliSec;
}
if (miliSec > 9) {
appendMiliSec.innerHTML = miliSec;
}
if (miliSec > 99) {
console.log("seconds");
seconds++;
appendSeconds.innerHTML = "0" + seconds;
miliSec = 0;
appendMiliSec.innerHTML = "0" + 0;
}
if (seconds > 9) {
appendSeconds.innerHTML = seconds;
}
if (seconds > 59) {
minitues++;
appendMinitues.innerHTML = "0" + minitues;
seconds = 0;
appendSeconds.innerHTML = "0" + seconds;
}
}
};