From 055f764bedc62997fdc7a3165f1b540a86806a13 Mon Sep 17 00:00:00 2001 From: Ranjeet Singh <93567891+Ranjeet0302Singh@users.noreply.github.com> Date: Fri, 28 Oct 2022 01:45:35 +0530 Subject: [PATCH] Create script.js --- 9-Color Full Digital & Analog Clock/script.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 9-Color Full Digital & Analog Clock/script.js diff --git a/9-Color Full Digital & Analog Clock/script.js b/9-Color Full Digital & Analog Clock/script.js new file mode 100644 index 00000000..7836272f --- /dev/null +++ b/9-Color Full Digital & Analog Clock/script.js @@ -0,0 +1,39 @@ +let hr = document.querySelector("#hr"); +let mn = document.querySelector("#mn"); +let sc = document.querySelector("#sc"); + +setInterval(() => { + let day = new Date(); + let hh = day.getHours() * 30; + let mm = day.getMinutes() * 6; + let ss = day.getSeconds() * 6; + + hr.style.transform = `rotateZ(${hh + mm / 12}deg)`; + mn.style.transform = `rotateZ(${mm}deg)`; + sc.style.transform = `rotateZ(${ss}deg)`; + + // Digital clock + let hours = document.getElementById("hours"); + let minutes = document.getElementById("minutes"); + let seconds = document.getElementById("seconds"); + let ampm = document.getElementById("ampm"); + + let h = new Date().getHours(); + let m = new Date().getMinutes(); + let s = new Date().getSeconds(); + + let am=h >=12?"PM":"AM"; + + if (h>12){ + h=h-12; + } + + h=(h<10)?"0"+h:h + m=(m<10)?"0"+m:m + s=(s<10)?"0"+s:s + + hours.innerHTML = h; + minutes.innerHTML = m; + seconds.innerHTML = s; + ampm.innerHTML=am; +});