Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
120 lines (101 loc) · 3.21 KB
/
Copy pathindex.html
File metadata and controls
120 lines (101 loc) · 3.21 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Digital Clock | Using Javascript</title>
<style type="text/css">
body{
background-color: black;
color: white;
}
.digitClock{
background-color: rgb(61, 59, 59);
height: 20vh;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto;
width: 50%;
font-size: 60px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
letter-spacing: 7px;
}
.stopWatch{
background-color: rgb(29, 26, 26);
height: 40vh;
align-items: center;
text-align: center;
margin: 0 auto;
width: 50%;
font-size: 60px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
letter-spacing: 7px;
}
button{
padding: 10px;
width: 20%;
margin: 0 5px;
border: none;
background-color: chartreuse;
}
</style>
</head>
<body>
<div class="digitClock" id="clock" onload="Clock()"></div>
<div class="stopWatch" id="stop">
<p><span id="tens">00</span> : <span id="seconds">00</span></p>
<button id="start" onclick="btnStart()">Start</button>
<button id="stop" onclick="btnStop()">Stop</button>
<button id="reset" onclick="btnReset()">Reset</button>
</div>
<script type="text/JavaScript">
function Clock(){
var date = new Date();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
h = (h < 10)? "0"+ h : h;
m = (m < 10)? "0" + m: m;
s = (s< 10)? "0" + s: s;
var time = h+" : "+m+" : "+s+" ";
document.getElementById("clock").innerText = time;
document.getElementsById("clock").textContent = time;
}
setInterval(Clock, 1000);
var tens = 00;
var seconds = 00;
var Interval;
function start() {
seconds++;
if (seconds == 100) {
seconds = 00;
tens++
}
if (seconds < 10) {
seconds = "0" + seconds;
}
document.getElementById("seconds").textContent = seconds;
if (tens >= 10) {
document.getElementById("tens").textContent = tens;
}else{
document.getElementById("tens").textContent = "0" + tens;
}
}
function btnStart() {
start();
Interval = setInterval(start, 10);
}
function btnStop() {
clearInterval(Interval);
}
function btnReset() {
seconds = 0;
tens = 0;
document.getElementById("seconds").textContent = "00";
document.getElementById("tens").textContent = "00";
}
</script>
</body>
</html>