-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
53 lines (44 loc) · 1.59 KB
/
main.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const DigitalClock = () => {
function updateClock() {
//initiating and assigning javascript date function to CurrentDate variable
let CurrentDate = new Date();
//Code for showing current hours
let Hour = CurrentDate.getHours().toLocaleString();
//Code for showing current minutes
let Minute = CurrentDate.getMinutes().toLocaleString();
//Code for showing current seconds
let Second = CurrentDate.getSeconds().toLocaleString();
//Initiating Hour, Minute and Second
let getHour = document.getElementById("hourid");
let getMinute = document.getElementById("minuteid");
let getSecond = document.getElementById("secondid");
//Showing the time in the html elements by targetting their id's
if (Hour <= 9) {
getHour.innerHTML = `${0 + Hour}:`;
} else if (Minute <= 9) {
getMinute.innerText = `${0 + Minute}:`;
} else if (Second <= 9) {
getSecond.innerText = `${0 + Second}`;
} else {
getHour.innerHTML = `${Hour}:`;
getMinute.innerText = `${Minute}:`;
getSecond.innerText = `${Second}`;
}
}
updateClock();
//code for update the clock every second
let oneSecond = 1000;
setInterval(updateClock, oneSecond);
const tickingSound = () => {
let volOn = document.getElementById("volume_on");
let volOff = document.getElementById("volume_off");
volOn.addEventListener("click", function () {
document.querySelector("audio").play();
});
volOff.addEventListener("click", function () {
document.querySelector("audio").pause();
});
};
tickingSound();
};
DigitalClock();