Skip to content

Commit 232dacd

Browse files
committed
feat: add JS script
1 parent 4aa5d40 commit 232dacd

File tree

2 files changed

+19
-101
lines changed

2 files changed

+19
-101
lines changed

‎02 - JS and CSS Clock/index-FINISHED.html‎

Lines changed: 0 additions & 100 deletions
This file was deleted.
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,26 @@
6868

6969
<script>
7070
const hourHand = document.querySelector(".hour-hand");
71-
const minHand = document.querySelector(".minsr-hand");
71+
const minHand = document.querySelector(".min-hand");
7272
const secondHand = document.querySelector(".second-hand");
73+
74+
const handDegreeChange = (time, max) => (time / max) * 360;
75+
76+
// Call function once every second
77+
setInterval(() => {
78+
const currentTime = new Date();
79+
// Get current seconds, minutes, & hours and calculate the degree shift
80+
const hourHandDegrees = handDegreeChange(currentTime.getHours(), 12);
81+
const minHandDegrees = handDegreeChange(currentTime.getMinutes(), 60);
82+
const secondHandDegrees = handDegreeChange(
83+
currentTime.getSeconds(),
84+
60
85+
);
86+
//Apply rotation to clock hands with current time
87+
hourHand.style.transform = `rotate(${hourHandDegrees}deg)`;
88+
minHand.style.transform = `rotate(${minHandDegrees}deg)`;
89+
secondHand.style.transform = `rotate(${secondHandDegrees}deg)`;
90+
}, 1000);
7391
</script>
7492
</body>
7593
</html>

0 commit comments

Comments
 (0)