-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
122 lines (100 loc) · 2.87 KB
/
Copy pathscript.js
File metadata and controls
122 lines (100 loc) · 2.87 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
let up = document.querySelector("#up");
let down = document.querySelector("#down");
let upt = document.querySelector("#uptime");
let dot = document.querySelector("#downtime");
let st = Number(prompt("Enter time in Minutes"));
let it = Number(prompt("Enter increment time"));
let intdo, intup;
let time = st * 60;
let p1time = time;
let p2time = time;
// Set initial MM:SS format
dot.innerText = formatTime(p1time);
upt.innerText = formatTime(p2time);
// Function to format seconds into MM:SS
function formatTime(time) {
let min = Math.floor(time / 60);
let sec = time % 60;
return `${String(min).padStart(2, '0')}:${String(sec).padStart(2, '0')}`;
}
function decreased() {
p1time--;
dot.innerText = formatTime(p1time);
if (p1time <= 0) {
clearInterval(intdo);
alert("Win on time");
}
if(p1time <=10){
let s = new Audio("audio/timepassing.mp3");
s.play();
}
}
function decrease() {
p2time--;
upt.innerText = formatTime(p2time);
if (p2time <= 0) {
clearInterval(intup);
alert("Win on time");
}
if(p2time <=10){
let s = new Audio("audio/timepassing.mp3");
s.play();
}
}
up.addEventListener("click", function () {
clearInterval(intup);
intdo = setInterval(decreased, 1000);
// Add increment
p2time += it;
upt.innerText = formatTime(p2time);
down.style.backgroundColor = "#4caf50";
up.style.backgroundColor = "white";
up.disabled = true;
down.disabled = false;
let beep = new Audio("audio/beep.mp3");
beep.play();
if(p2time <=10){
let s = new Audio("timepassing.mp3");
s.play();
}
});
down.addEventListener("click", function () {
clearInterval(intdo);
intup = setInterval(decrease, 1000);
p1time += it;
dot.innerText = formatTime(p1time);
up.style.backgroundColor = "#4caf50";
down.style.backgroundColor = "white";
down.disabled = true;
up.disabled = false;
let beep = new Audio("audio/beep.mp3");
beep.play();
if(p1time <=10){
let s = new Audio("audio/timepassing.mp3");
s.play();
}
});
let res = document.querySelector("#reset")
let play = document.querySelector("#play")
res.addEventListener("click",function dd(){
location.reload()
})
let isPaused = false; // Track pause/resume state
play.addEventListener("click", function () {
if (!isPaused) {
// Pause both intervals
clearInterval(intup);
clearInterval(intdo);
isPaused = true;
play.innerText = "Resume";
} else {
// Resume based on which button is disabled
if (up.disabled) {
intdo = setInterval(decreased, 1000);
} else if (down.disabled) {
intup = setInterval(decrease, 1000);
}
isPaused = false;
play.innerText = "Pause";
}
});