-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (24 loc) · 750 Bytes
/
index.js
File metadata and controls
28 lines (24 loc) · 750 Bytes
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
const hourEl = document.getElementById("hour");
const minuteEl = document.getElementById("minutes");
const secondEl = document.getElementById("seconds");
const ampmEl = document.getElementById("ampm");
const updateClock = () => {
let hour = new Date().getHours();
let minutes = new Date().getMinutes();
let seconds = new Date().getSeconds();
let ampm = "AM";
if (hour > 12) {
hour = hour - 12;
ampm = "PM";
} else if(hour == 12) {
ampm = "PM"
}
hourEl.innerText = hour < 10 ? "0" + hour : hour;
minuteEl.innerText = minutes < 10 ? "0" + minutes : minutes;
secondEl.innerText = seconds < 10 ? "0" + seconds : seconds;
ampmEl.innerText = ampm;
setTimeout(() => {
updateClock();
}, 1000);
};
updateClock();