Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Mandatory Alarm Clock is done
Alarm Clock
  • Loading branch information
murselaysan committed Aug 1, 2020
commit 21852dc0500512aa991a5cd0c929909c6aad30dc
33 changes: 32 additions & 1 deletion Week-3/Homework/mandatory/1-alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
function setAlarm() {}
function setAlarm() {
let inputTime = document.getElementById("alarmSet").value;
let timeRemaining = document.getElementById("timeRemaining");

function timeFormat(time) {
let allMinutes;
let seconds;
if (time > 60) {
allMinutes = Math.floor(time / 60);
seconds = time - allMinutes * 60;
} else {
allMinutes = 0;
seconds = time;
}
if (allMinutes < 10) {
allMinutes = "0" + allMinutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}
return `${allMinutes}:${seconds}`;
}

let alarm = setInterval(() => {
if (inputTime === 0) {
playAlarm();
clearInterval(alarm);
}
timeRemaining.textContent = `Time remaining: ${timeFormat(inputTime)}`;
inputTime--;
}, 1000);
}

// DO NOT EDIT BELOW HERE

Expand Down