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
44 changes: 42 additions & 2 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
function setAlarm() {}
// Only define Audio if it doesn't exist (Node environment)
if (typeof Audio === "undefined") {
global.Audio = class {
constructor(src) {
this.src = src;
}
play() {}
pause() {}
};
}

let intervalId;

const formatTime = (s) => {
const mins = Math.floor(s / 60);
const secs = s % 60;
return `${String(mins).padStart(2, "0")}:${String(secs).padStart(2, "0")}`;
};

function setAlarm() {
const input = document.getElementById("alarmSet");
const timer = document.getElementById("timeRemaining");

const seconds = parseInt(input.value);
if (isNaN(seconds) || seconds < 0) return;

let remaining = seconds;

// DO NOT EDIT BELOW HERE
timer.textContent = `Time Remaining: ${formatTime(remaining)}`;

if (intervalId) clearInterval(intervalId);

intervalId = setInterval(() => {
remaining--;

timer.textContent = `Time Remaining: ${formatTime(remaining)}`;

if (remaining <= 0) {
clearInterval(intervalId);
playAlarm();
}
}, 1000);
}

var audio = new Audio("alarmsound.mp3");

Expand Down
4 changes: 2 additions & 2 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<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 app</title>
</head>
<body>
<div class="centre">
Expand Down
Empty file added Sprint-3/alarmclock/{
Empty file.
6 changes: 0 additions & 6 deletions Sprint-3/jest.setup.js

This file was deleted.

32 changes: 0 additions & 32 deletions Sprint-3/package.json

This file was deleted.

Loading