forked from KTibow/web-timer-KTibow-and-ejrejr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebTimer.html
88 lines (69 loc) · 1.85 KB
/
webTimer.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
<html>
<!-- saved from url=(0014)about:internet -->
<head>
<title>Web Timer Project</title>
<script>
var seconds = 0;
var minutes = 0;
var hours = 0;
var timeoutActive = false;
function StartTimer()
{
var inputTime = startTime.value;
var times = inputTime.split(":");
if (times.length == 1) {
seconds = times[0];
}
if (times.length == 2) {
minutes = times[0];
seconds = times[1];
}
if (times.length == 3) {
hours = times[0];
minutes = times[1];
seconds = times[2];
}
timeHours.innerText = hours;
timeMinutes.innerText = minutes;
timeSeconds.innerText = seconds;
if (timeoutActive == false) {
setTimeout(UpdateTimer, 900);
timeoutActive = true;
}
}
function UpdateTimer()
{
if (hours == 0 && minutes == 0 && seconds == 0) {
timeoutActive = false;
return;
}
seconds = seconds - 1;
if (seconds < 0) {
seconds = 59;
minutes = minutes - 1;
}
if (minutes < 0) {
minutes = 59;
hours = hours - 1;
}
if (hours < 0)
{
hours = 0;
}
timeHours.innerText = hours;
timeMinutes.innerText = minutes;
timeSeconds.innerText = seconds;
setTimeout(UpdateTimer, 900);
}
</script>
</head>
<body>
<h1>
Web Timer Project
</h1>
<p>Input the start of the timer - use a colon between hour, minutes, and seconds.</p>
<p>Input your time value: <input id="startTime" /> : <button onclick="StartTimer();">Start Timer</button></p>
<p>---</p>
<p><span id="timeHours">00</span> : <span id="timeMinutes">00</span> : <span id="timeSeconds">00</span></p>
</body>
</html>