-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
29 lines (24 loc) · 856 Bytes
/
script.js
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
29
//Grabbing elements from the dom
const hour=document.getElementById('hour');
const minute=document.getElementById('minute');
const second=document.getElementById('second')
//Function to rotate the hand
const rotateHand=(element,degree)=>{
element.style.setProperty('--degree-of-rotation',degree);
}
//Function to set the clock
const setClock=()=>{
const currentTime=new Date();
const currentHour=currentTime.getHours();
const currentMinute=currentTime.getMinutes();
const currentSeconds=currentTime.getSeconds();
let hourDegree=(currentHour/12)*360;
let minuteDegree=(currentMinute/60)*360;
let secondDegree=(currentSeconds/60)*360;
rotateHand(hour,hourDegree);
rotateHand(minute,minuteDegree);
rotateHand(second,secondDegree);
}
//Invoke the function in each second
setInterval(setClock,1000);
setClock();