Update script.js
Browse files
script.js
CHANGED
|
@@ -1,29 +1,42 @@
|
|
| 1 |
-
function showTime(){
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
if(h == 0){
|
| 9 |
h = 12;
|
| 10 |
}
|
| 11 |
-
|
| 12 |
-
if(h > 12){
|
| 13 |
h = h - 12;
|
| 14 |
session = "PM";
|
| 15 |
}
|
| 16 |
-
|
| 17 |
h = (h < 10) ? "0" + h : h;
|
| 18 |
m = (m < 10) ? "0" + m : m;
|
| 19 |
s = (s < 10) ? "0" + s : s;
|
| 20 |
-
|
| 21 |
-
|
| 22 |
document.getElementById("MyClockDisplay").innerText = time;
|
| 23 |
document.getElementById("MyClockDisplay").textContent = time;
|
| 24 |
-
|
| 25 |
setTimeout(showTime, 1000);
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
|
| 29 |
showTime();
|
|
|
|
| 1 |
+
function showTime() {
|
| 2 |
+
const date = new Date();
|
| 3 |
+
let h = date.getHours(); // 0 - 23
|
| 4 |
+
let m = date.getMinutes(); // 0 - 59
|
| 5 |
+
let s = date.getSeconds(); // 0 - 59
|
| 6 |
+
let session = "AM";
|
| 7 |
+
|
| 8 |
+
if (h == 0) {
|
| 9 |
h = 12;
|
| 10 |
}
|
| 11 |
+
|
| 12 |
+
if (h > 12) {
|
| 13 |
h = h - 12;
|
| 14 |
session = "PM";
|
| 15 |
}
|
| 16 |
+
|
| 17 |
h = (h < 10) ? "0" + h : h;
|
| 18 |
m = (m < 10) ? "0" + m : m;
|
| 19 |
s = (s < 10) ? "0" + s : s;
|
| 20 |
+
|
| 21 |
+
const time = h + ":" + m;
|
| 22 |
document.getElementById("MyClockDisplay").innerText = time;
|
| 23 |
document.getElementById("MyClockDisplay").textContent = time;
|
| 24 |
+
|
| 25 |
setTimeout(showTime, 1000);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
function toggleMenu() {
|
| 29 |
+
const menu = document.getElementById('colorMenu');
|
| 30 |
+
if (menu.style.display === 'none' || menu.style.display === '') {
|
| 31 |
+
menu.style.display = 'block';
|
| 32 |
+
} else {
|
| 33 |
+
menu.style.display = 'none';
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
function changeColor(color) {
|
| 38 |
+
document.querySelector('.clock').style.color = color;
|
| 39 |
+
document.getElementById('colorMenu').style.display = 'none';
|
| 40 |
}
|
| 41 |
|
| 42 |
showTime();
|