-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
102 lines (96 loc) · 2.99 KB
/
main.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
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
var inputHour;
var inputMinute;
var inputSecond;
var outputHour = document.getElementById("outputHour");
var outputMinute = document.getElementById("outputMinute");
var outputSecond = document.getElementById("outputSecond");
var startBtn = document.getElementById("startBtn");
var stopBtn = document.getElementById("stopBtn");
var timerApp;
var outputContainer = document.getElementById("outputContainer");
function StartClock()
{
inputHour = Number(document.getElementById("inputHour").value);
inputMinute = Number(document.getElementById("inputMinute").value);
inputSecond = Number(document.getElementById("inputSecond").value);
if(inputHour > 0 || (inputMinute > 0 && inputMinute < 60)|| (inputSecond > 0 && inputSecond < 60))
{
outputHour.innerHTML = FormatTime(inputHour);
outputMinute.innerHTML = FormatTime(inputMinute);
outputSecond.innerHTML = FormatTime(inputSecond);
outputContainer.style.display = "flex";
startBtn.style.display = "none";
stopBtn.style.display = "inline-block";
timerApp = setInterval(myClock, 1000);
}
else
{
document.getElementById("inputHour").value = "";
document.getElementById("inputMinute").value = "";
document.getElementById("inputSecond").value = "";
alert("Enter valid time.");
}
}
function StopClock()
{
startBtn.style.display = "inline-block";
stopBtn.style.display = "none";
outputHour.innerHTML = "00";
outputMinute.innerHTML = "00";
outputSecond.innerHTML = "00";
clearInterval(timerApp);
}
function ResetClock()
{
StopClock();
outputContainer.style.display = "none";
document.getElementById("inputHour").value = "";
document.getElementById("inputMinute").value = "";
document.getElementById("inputSecond").value = "";
outputHour.innerHTML = "00";
outputMinute.innerHTML = "00";
outputSecond.innerHTML = "00";
inputHour = 0;
inputMinute = 0;
inputSecond = 0;
}
function myClock()
{
if(inputSecond > 0){
inputSecond--;
outputSecond.innerHTML = FormatTime(inputSecond);
}else{
if(inputMinute > 0){
inputMinute--;
outputMinute.innerHTML = FormatTime(inputMinute);
inputSecond = 59;
outputSecond.innerHTML = FormatTime(inputSecond);
}else{
if(inputHour > 0){
inputHour--;
outputHour.innerHTML = FormatTime(inputHour);
inputMinute = 59;
outputMinute.innerHTML = FormatTime(inputMinute);
inputSecond = 59;
outputSecond.innerHTML = FormatTime(inputSecond);
}else{
StopClock();
new Audio('./beep.mp3').play()
return;
}
}
}
}
function FormatTime(time)
{
var formatedTime
if(time < 10)
{
formatedTime = "0" + time.toString();
}
else
{
formatedTime = time.toString();
}
return formatedTime
}