diff --git a/JavaScript/Alarm_Clock/Readme.md b/JavaScript/Alarm_Clock/Readme.md new file mode 100644 index 00000000..e5a4060c --- /dev/null +++ b/JavaScript/Alarm_Clock/Readme.md @@ -0,0 +1,10 @@ +# Alarm Clock + +A website for alarm clock. + +## How to use the script ? + +Open index.html in any browser. + +## Screenshot +![demo](https://user-images.githubusercontent.com/56690856/99620214-18af7d80-2a4b-11eb-8f07-dfbf52b9df48.png) diff --git a/JavaScript/Alarm_Clock/audio.mp3 b/JavaScript/Alarm_Clock/audio.mp3 new file mode 100644 index 00000000..3913e2f4 Binary files /dev/null and b/JavaScript/Alarm_Clock/audio.mp3 differ diff --git a/JavaScript/Alarm_Clock/index.html b/JavaScript/Alarm_Clock/index.html new file mode 100644 index 00000000..23028e9e --- /dev/null +++ b/JavaScript/Alarm_Clock/index.html @@ -0,0 +1,24 @@ + + + + + + Alarm Clock + + + +
+
+ +

Enter the time in yyyy-mm-dd hh:mm:ss

+
+ + +
+
+ + + + \ No newline at end of file diff --git a/JavaScript/Alarm_Clock/index.js b/JavaScript/Alarm_Clock/index.js new file mode 100644 index 00000000..d5f1bd16 --- /dev/null +++ b/JavaScript/Alarm_Clock/index.js @@ -0,0 +1,35 @@ +const alarmSubmit = document.getElementById("alarmSubmit"); +const alarmStop = document.getElementById("alarmStop"); +const audio = document.getElementById("alarmAudio"); + +// Add an event listener to the submit button +alarmSubmit.addEventListener("click", setAlarm); + +// Add an event listener to the stop button +alarmStop.addEventListener("click", stopAlarm); + +// function to play the alarm ring tone +function ringBell() { + audio.play(); +} + +// function to set alarm +function setAlarm(e) { + e.preventDefault(); + const alarm = document.getElementById("alarm"); + alarmDate = new Date(alarm.value); + now = new Date(); + console.log(now); + let timeToAlarm = alarmDate - now; + console.log(timeToAlarm); + if (timeToAlarm >= 0) { + setTimeout(() => { + ringBell(); + }, timeToAlarm); + } +} + +// function to stop alarm +function stopAlarm(e) { + audio.pause(); +} diff --git a/JavaScript/Alarm_Clock/style.css b/JavaScript/Alarm_Clock/style.css new file mode 100644 index 00000000..1368e5da --- /dev/null +++ b/JavaScript/Alarm_Clock/style.css @@ -0,0 +1,38 @@ +body { + background-color: #fecd1a; +} + +.container { + background-color: black; + color: white; + padding: 30px; + text-align: center; + margin: auto; + width: 50%; + margin-top: 10%; + border-radius: 30px; +} + +h1{ + font-size:60px +} + +h2 { + font-size: 40px; +} + +.btn{ + margin: 25px; + font-size: 25px; + border-color: chartreuse; + border-width: 5px; +} + +#alarm{ + font-size: 30px; + padding: 10px; +} + +::placeholder{ + color: black; +} \ No newline at end of file