-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·39 lines (34 loc) · 1.14 KB
/
app.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
30
31
32
33
34
35
36
37
38
39
const digiTime = document.querySelector('p')
const secondHand = document.querySelector('.second-hand');
const minsHand = document.querySelector('.min-hand');
const hourHand = document.querySelector('.hour-hand');
function addZero(i) {
if (i < 10) {
i = "0" + i
}
return i
}
function setDigiClock () {
const now = new Date()
const hours = now.getHours()
const minutes = now.getMinutes()
const seconds = now.getSeconds()
const time = addZero(hours) + ":" + addZero(minutes) + ":" + addZero(seconds)
digiTime.textContent = time
}
function setAnalogueClock() {
const now = new Date()
const seconds = now.getSeconds()
const secondsDegrees = ((seconds / 60) * 360) + 90
secondHand.style.transform = `rotate(${secondsDegrees}deg)`
const mins = now.getMinutes()
const minsDegrees = ((mins / 60) * 360) + ((seconds/60)*6) + 90
minsHand.style.transform = `rotate(${minsDegrees}deg)`
const hour = now.getHours()
const hourDegrees = ((hour / 12) * 360) + ((mins/60)*30) + 90
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
}
setInterval(setDigiClock, 1000)
setInterval(setAnalogueClock, 1000)
setDigiClock()
setAnalogueClock()