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() {}
let alarmInterval;
let timeRemaining = 0;

function setAlarm() {
// Get the input value
const alarmInput = document.getElementById("alarmSet");
const seconds = parseInt(alarmInput.value);

// Validate input
if (isNaN(seconds) || seconds <= 0) {
alert("Please enter a valid number of seconds!");
return;
}

// Clear any existing interval
if (alarmInterval) {
clearInterval(alarmInterval);
}

// Set the time remaining
timeRemaining = seconds;

// Update the display immediately
updateDisplay();

// Start the countdown
alarmInterval = setInterval(() => {
timeRemaining--;
updateDisplay();

// Check if time is up
if (timeRemaining <= 0) {
clearInterval(alarmInterval);
playAlarm();
}
}, 1000);
}

function updateDisplay() {
const minutes = Math.floor(timeRemaining / 60);
const seconds = timeRemaining % 60;

// Format with leading zeros
const formattedTime = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;

// Update the display
document.getElementById("timeRemaining").textContent = `Time Remaining: ${formattedTime}`;
}

// 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 app</title>
</head>
<body>
<div class="centre">
Expand Down