|
1 | 1 | let countdownInterval = null; |
2 | 2 | let secondsLeft = 0; |
| 3 | +const heading = document.getElementById("timeRemaining"); |
3 | 4 |
|
4 | 5 | function setAlarm() { |
5 | | - // Read the number of minutes from the input field (expects minutes) |
| 6 | + // Read the number of seconds from the input field |
6 | 7 | const input = document.getElementById("alarmSet"); |
7 | | - const minutes = parseInt(input.value, 10); |
| 8 | + const seconds = parseInt(input.value, 10); |
8 | 9 |
|
9 | 10 | // If nothing useful was entered, do nothing |
10 | | - if (isNaN(minutes) || minutes <= 0) { |
| 11 | + if (isNaN(seconds) || seconds <= 0) { |
11 | 12 | return; |
12 | 13 | } |
13 | 14 |
|
14 | | - // Store the remaining time; currently this value is in minutes (not seconds yet) |
15 | | - secondsLeft = minutes; |
16 | | - |
| 15 | + // Use seconds directly |
| 16 | + secondsLeft = seconds; |
17 | 17 | // Stop any existing countdown |
18 | 18 | if (countdownInterval !== null) { |
19 | 19 | clearInterval(countdownInterval); |
@@ -46,11 +46,8 @@ function setAlarm() { |
46 | 46 | function updateTimeDisplay() { |
47 | 47 | const minutes = Math.floor(secondsLeft / 60); |
48 | 48 | const seconds = secondsLeft % 60; |
49 | | - |
50 | 49 | const displayMin = minutes.toString().padStart(2, "0"); |
51 | 50 | const displaySec = seconds.toString().padStart(2, "0"); |
52 | | - |
53 | | - const heading = document.getElementById("timeRemaining"); |
54 | 51 | heading.textContent = `Time Remaining: ${displayMin}:${displaySec}`; |
55 | 52 | } |
56 | 53 |
|
|
0 commit comments