-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
159 lines (144 loc) · 4.87 KB
/
index.html
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Countdown</title>
<style>
@font-face {
font-family: Segment;
src: url(DSEG7Classic-Bold.ttf);
}
body {
background-color: black;
}
#container {
margin-top:100px;
height: 100;
color: red;
font-family: Segment;
font-size: 150px;
}
#buttons {
margin-top: 50px;
display: flex;
justify-content: center;
}
#displaycase {
display: flex;
justify-content: center;
align-items: center;
}
.display {
margin-top: 60px;
margin-bottom: 60px;
}
.inverted {
background-color: red;
color: black;
}
.black {
color: black;
}
button {
padding: 15px;
cursor: pointer;
background-color: black;
color: darkgreen;
font-size: 60px;
}
</style>
</head>
<body>
<div id="container">
<div id="displaycase">
<span id="hours" class="display">00</span>
<span id="colon2" class="display">:</span>
<span id="minutes" class="display">00</span>
<span id="colon" class="display">:</span>
<span id="seconds" class="display">00</span>
</div>
<div id="buttons">
<button onclick="startTimer()">▶</button>
<button onclick="stopTimer()">⏹</button>
<button onclick="resetTimer()">↩</button>
<button onclick="setMinutes()">⬇</button>
</div>
</div>
<script>
const START_TIME = 60 * 15
let countdown;
let countdownTime = START_TIME;//0 * 60; // Countdown from 5 minutes (300 seconds)
const minutes = document.getElementById('minutes');
const seconds = document.getElementById('seconds');
const hours = document.getElementById('hours');
const colon = document.getElementById('colon');
const colon2 = document.getElementById('colon2');
const display = document.getElementById('displaycase');
function formatHours(seconds) {
var m = Math.floor(seconds / 60)
var h = Math.floor(m / 60).toString();
if (h.length < 2) h = `0${h}`;
return h;
}
function formatMinutes(seconds) {
var m = Math.floor(seconds / 60).toString();
var remainingMinutes = (m % 60).toString();
if (remainingMinutes.length < 2) remainingMinutes = `0${remainingMinutes}`;
return remainingMinutes;
}
function formatSeconds(seconds) {
var remainingSeconds = (seconds % 60).toString();
if (remainingSeconds.length < 2) remainingSeconds = `0${remainingSeconds}`;
return remainingSeconds.toString();
}
function updateDisplay() {
hours.textContent = formatHours(countdownTime)
hours.hidden = hours.textContent == "00"
colon2.hidden = hours.textContent == "00"
minutes.textContent = formatMinutes(countdownTime);
seconds.textContent = formatSeconds(countdownTime);
}
function setMinutes() {
resetTimer()
let promptAnswer
do {
promptAnswer = parseInt(prompt("Please enter a number minutes to set the timer", "59"));
}
while (isNaN(promptAnswer))
countdownTime = parseInt(promptAnswer) * 60
updateDisplay();
}
function timer() {
countdownTime--;
updateDisplay();
if (countdownTime <= 0.0) {
minutes.textContent = "00";
seconds.textContent = "00";
hours.textContent = "00";
hours.hidden = hours.textContent == "00"
colon2.hidden = hours.textContent == "00"
display.classList.toggle("inverted")
}
colon.classList.toggle("black");
colon2.classList.toggle("black");
}
function startTimer() {
clearInterval(countdown);
countdown = setInterval(timer, 1000);
}
function stopTimer() {
clearInterval(countdown);
display.classList.remove("inverted")
colon.classList.remove("black");
colon2.classList.remove("black");
}
function resetTimer() {
stopTimer();
countdownTime = START_TIME; // Reset to 5 minutes
display.classList.remove("inverted")
updateDisplay();
}
updateDisplay(); // Initialize display
</script>
</body>
</html>