-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclock.js
36 lines (26 loc) · 1.22 KB
/
clock.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
var secHand = document.querySelector('.second-hand');
var minHand = document.querySelector('.min-hand');
var hourHand = document.querySelector('.hour-hand');
var digitalClock = document.querySelector('.digital-clock');
var audio = document.querySelector('audio');
setInterval(playClock, 1000);
function playClock() {
var date = new Date;
var getSec = date.getSeconds();
var getMin = date.getMinutes();
var getHour = date.getHours();
//********************* Analog clock*******************************
secHand.style.setProperty('transform' , `rotate(${(getSec * 6) + 90 }deg)`);
minHand.style.setProperty('transform' , `rotate(${(getMin * 6) + 90 }deg)`);
hourHand.style.setProperty('transform' , `rotate(${(getHour * 30) + 90 }deg`);
//********************* Digital clock*******************************
var ampm = getHour < 12 ? 'AM' : 'PM';
// override for digital clock
getSec = getSec < 10 ? `0${getSec}` : getSec;
getMin = getMin < 10 ? `0${getMin}` : getMin;
getHour = getHour % 12;
getHour = getHour < 10 ? '0' + getHour : getHour;
digitalClock.textContent = `${getHour} : ${getMin} : ${getSec} ${ampm}`;
audio.volume = .2; // 20% volume
audio.play();
}