Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
49 changes: 48 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,51 @@
function setAlarm() {}
//this variable holds the time independent of the function
let Timer = null;

function setAlarm() {
//this pulls the set time from whatever is entered as input on the html page
let inputValue = document.getElementById("alarmSet").value;

let remainingTime = Number(inputValue);

if (isNaN(remainingTime) || remainingTime <= 0) {
return;
}

//Time on screen in MM:SS format
updateTimerDisplay(remainingTime);

if (Timer !== null) {
clearInterval(Timer);
}

Timer = setInterval(function () {
remainingTime = remainingTime - 1; //timer is reduced by 1 second

updateTimerDisplay(remainingTime); //then updated

// When timer hits zero, stop timer and play alarm
if (remainingTime <= 0) {
clearInterval(Timer);
playAlarm();
}
}, 1000);
}


function updateTimerDisplay(seconds) {
let minutes = Math.floor(seconds / 60);
let secs = seconds % 60;

// Puts the figures in strings and in a clock-like format
let minuteStr = String(minutes).padStart(2, "0");
let secondStr = String(secs).padStart(2, "0");

// Update the heading text
document.getElementById(
"timeRemaining"
).innerText = `Time Remaining: ${minuteStr}:${secondStr}`;

}

// DO NOT EDIT BELOW HERE

Expand Down
2 changes: 1 addition & 1 deletion Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Title here</title>
<title>Alarm Clock</title>
</head>
<body>
<div class="centre">
Expand Down