Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
120 lines (106 loc) · 3.36 KB
/
Copy pathscript.js
File metadata and controls
120 lines (106 loc) · 3.36 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const selection = document.querySelectorAll("select");
const currenttime = document.querySelector("h1");
const AlarmBtn = document.querySelector("button");
const ClearBtn = document.getElementById("cl-b");
const content = document.querySelector(".content");
const displayAlm = document.getElementById("alarm-list");
var gif = document.getElementById("clock");
let alarmTime = [];
let index = 0;
let ringtone = new Audio("./files/Goofy cartoon sounds.mp3");
let isAlarmSet = false;
//creating selections to select time
for (let i = 12; i > 0; i--) {
i = i < 10 ? "0" + i : i;
let option = `<option value="${i}">${i}</option>`;
selection[0].firstElementChild.insertAdjacentHTML("afterend", option);
}
for (let i = 59; i >= 0; i--) {
i = i < 10 ? "0" + i : i;
let option = `<option value="${i}">${i}</option>`;
selection[1].firstElementChild.insertAdjacentHTML("afterend", option);
}
for (let i = 59; i >= 0; i--) {
i = i < 10 ? "0" + i : i;
let option = `<option value="${i}">${i}</option>`;
selection[2].firstElementChild.insertAdjacentHTML("afterend", option);
}
for (let i = 2; i > 0; i--) {
let ap = i == 1 ? "AM" : "PM";
let option = `<option value="${ap}">${ap}</option>`;
selection[3].firstElementChild.insertAdjacentHTML("afterend", option);
}
//msking clock work
setInterval(() => {
let date = new Date(),
h = date.getHours(),
m = date.getMinutes(),
s = date.getSeconds(),
ap = "AM";
if (h >= 12) {
h = h - 12;
ap = "PM";
}
//if hour= 0 then set this value as 12
h = h == 0 ? (h = 12) : h;
//adding 0s to single digit values
h = h < 10 ? "0" + h : h;
m = m < 10 ? "0" + m : m;
s = s < 10 ? "0" + s : s;
//displaying the clock
currenttime.innerText = `${h}:${m}:${s} ${ap}`;
for (let j = 0; j <= alarmTime.length; j++) {
if (alarmTime[j] === `${h}:${m}:${s} ${ap}`) {
gif.src = "./files/gfff.gif";
ringtone.play();
ringtone.loop = true;
}
}
}, 1000);
function setAlarm() {
//getting exact time value
let time = `${selection[0].value}:${selection[1].value}:${selection[2].value} ${selection[3].value}`;
//setting checks for invalid alarms
if (
time.includes("Hour") ||
time.includes("Minute") ||
time.includes("Seconds") ||
time.includes("AM/PM")
) {
return alert("enter valid time");
}
isAlarmSet = true;
alarmTime.push(time);
for (let d = 0; d < alarmTime.length; d++) {
console.log(alarmTime[d]);
}
//alarmTime = time;
// content.classList.add("disable");
var para = document.createElement("p");
para.innerText = `${selection[0].value}:${selection[1].value}:${selection[2].value} ${selection[3].value}`;
displayAlm.appendChild(para);
var btn = document.createElement("button");
btn.innerHTML = "delete alarm ";
btn.addEventListener("click", deleteAlarm);
displayAlm.appendChild(btn);
}
AlarmBtn.addEventListener("click", setAlarm);
function clearAlarm() {
if (isAlarmSet) {
for (let z = 0; z < alarmTime.length; z++) {
alarmTime[z] = alarmTime[z + 1];
}
alarmTime.length = alarmTime.length - 1;
gif.src = "./files/alarm-clock-svgrepo-com.svg";
ringtone.pause();
for (let d = 0; d < alarmTime.length; d++) {
console.log(alarmTime[d]);
}
return (isAlarmSet = false);
}
}
ClearBtn.addEventListener("click", clearAlarm);
function deleteAlarm() {
displayAlm.parentNode.removeChild(displayAlm);
alarmTime = [];
}