Skip to content

Commit 70e564a

Browse files
Update main.js
1 parent 048d459 commit 70e564a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

project-10-digital-clock/main.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,24 @@ function updateClock () {
1212
let m = new Date().getMinutes();
1313
let s = new Date().getSeconds();
1414
let ampm = "AM";
15-
15+
1616
if (h > 12) {
1717
h = h - 12;
1818
ampm = "PM";
1919
}
20+
21+
h = h < 10 ? "0" + h : h;
22+
m = m < 10 ? "0" + m : m;
23+
s = s < 10 ? "0" + s : s;
2024

2125
hourEl.innerText = h;
2226
minuteEl.innerText = m;
2327
secondEl.innerText = s;
2428
ampmEl.innerText = ampm;
29+
30+
setTimeout(()=>{
31+
updateClock();
32+
}, 1000);
2533
}
2634

2735
updateClock();

0 commit comments

Comments
 (0)