-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
64 lines (58 loc) · 1.6 KB
/
app.js
File metadata and controls
64 lines (58 loc) · 1.6 KB
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
64
const ringer=document.getElementById("end");
const sound = document.getElementById("bgm");
const startBtn = document.querySelector('.start');
const session = document.querySelector('.min');
const sec = document.querySelector('.sec');
const button=document.getElementById("button");
let myInterval=null;
let state = true;
let totalSeconds;
const appTimer = () =>
{
const sessionAmount = Number.parseInt(session.textContent)
const secamt=Number.parseInt(sec.textContent)
if(state) {
state = false;
button.textContent="STOP";
totalSeconds = (sessionAmount * 60)+secamt;
const updateSeconds = () =>
{
totalSeconds--;
let minutesLeft
if(totalSeconds>=60){
minutesLeft = Math.floor(totalSeconds/60);
}
else {minutesLeft=0}
let secondsLeft = totalSeconds % 60;
if(secondsLeft < 10)
{
sec.textContent = '0' + secondsLeft;
}
else{
sec.textContent = secondsLeft;
}
session.textContent = `${minutesLeft}`
if(minutesLeft === 0 && secondsLeft === 0)
{ sound.pause();
sound.currentTime = 0;
ringer.play();
clearInterval(myInterval);
session.textContent='1';
sec.textContent='00';
}
else{
sound.play();
}
}
myInterval = setInterval(updateSeconds, 1000);
}
else{
state=true;
button.textContent="start"
clearInterval(myInterval);
myInterval=null;
sound.pause();
sound.currentTime = 0;
}
}
startBtn.addEventListener('click', appTimer);