-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (40 loc) · 1.09 KB
/
index.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
let seconds = 00;
let tens = 00;
let appendTens = document.getElementById("tens");
let appendSeconds = document.getElementById("seconds");
let buttonStart = document.getElementById("button-start");
let buttonstop = document.getElementById("button-stop");
let buttonReset = document.getElementById("button-reset");
var interval; //store value
//this fuction runs when click start
let startTimer= () =>{
tens++;
if(tens<9){
appendTens.innerHTML = "0"+ tens;
}
if(tens>9){
appendTens.innerHTML = tens;
}
if(tens>60){
seconds++;
appendSeconds.innerHTML = "0"+ seconds;
tens=0;
appendTens.innerHTML = "0"+0;
}
if(seconds>9){
appendSeconds.innerHTML = seconds;
}
}
buttonStart.onclick = function(){
interval = setInterval(startTimer);
}
buttonstop.onclick = function(){
clearInterval(interval);
}
buttonReset.onclick = function(){
clearInterval(interval);
tens = "00";
seconds = "00";
appendSeconds.innerHTML = seconds;
appendTens.innerHTML = tens;
}