From 578ae9ab1661993a53fed8da028c37b13153f967 Mon Sep 17 00:00:00 2001 From: Syed Naqi Abbas <68586379+syed-naqi-abbas@users.noreply.github.com> Date: Wed, 18 Dec 2024 13:31:15 +0530 Subject: [PATCH] Add files via upload --- alarm/alarm.html | 27 +++++++++++++++++++++ alarm/alarm.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 alarm/alarm.html create mode 100644 alarm/alarm.js diff --git a/alarm/alarm.html b/alarm/alarm.html new file mode 100644 index 0000000..1a4ed75 --- /dev/null +++ b/alarm/alarm.html @@ -0,0 +1,27 @@ + + + + + + Alarm Clock + + + +
+

+ Alarm Clock +

+
+
+ +
+ +
+
+
+ +
+ + + + \ No newline at end of file diff --git a/alarm/alarm.js b/alarm/alarm.js new file mode 100644 index 0000000..8b6046b --- /dev/null +++ b/alarm/alarm.js @@ -0,0 +1,62 @@ +let num=0; +let grid = document.getElementById("grid"); +let bell = new Audio("bell.wav"); +function addNewAlarm(){ + let insert = `
+
+
+ Create New Alarm +
+ +
+
`; + grid.insertAdjacentHTML('beforeend',insert) + num++; +} +function delay(){ + return new Promise((resolve,reject)=>{ + setTimeout(()=>{ + resolve(1); + },1000); + }) +} +async function create(mynum){ + let h = Number.parseInt(document.getElementById(`card${mynum}h`).value) + let m = Number.parseInt(document.getElementById(`card${mynum}m`).value) + let s = Number.parseInt(document.getElementById(`card${mynum}s`).value) + let time = h*60*60 + m*60 + s; + + let mydiv = document.getElementById(mynum.toString()) + + for(let i=1;i<=time;i++){ + mydiv.innerHTML = `
+
+ Alarm +
+
+

${h} : ${m} : ${s}

+
+
` + await delay(); + if(s==0) { + s=60; + if(m==0){ + h--; + m=60; + } + m--; + } + s--; + } + console.log(`${mynum} just got over`); + bell.play(); + mydiv.replaceWith(""); +} + +let newAlarm = document.getElementById("newAlarm") +newAlarm.addEventListener('click',addNewAlarm) \ No newline at end of file