Skip to content

Commit d48ff25

Browse files
committed
event handling callback function method changed
1 parent 1e92123 commit d48ff25

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ function updateDisplay() {
1818
const heading = document.getElementById("timeRemaining");
1919
const input = document.getElementById("alarmSet");
2020

21-
// clamp BEFORE formatting
2221
totalSeconds = Math.max(0, totalSeconds);
2322
const formatted = formatTime(totalSeconds);
2423

@@ -27,7 +26,6 @@ function updateDisplay() {
2726
}
2827

2928
function incrementTime(amount) {
30-
// correctly ADD or SUBTRACT 5 seconds
3129
totalSeconds = Math.max(0, totalSeconds + amount);
3230
updateDisplay();
3331
}
@@ -48,7 +46,7 @@ function setAlarm() {
4846

4947
timer = setInterval(() => {
5048
totalSeconds--;
51-
totalSeconds = Math.max(0, totalSeconds); // clamp again for safety
49+
totalSeconds = Math.max(0, totalSeconds);
5250
updateDisplay();
5351

5452
if (totalSeconds === 0) {
@@ -67,10 +65,10 @@ function stopTimer() {
6765
audio.pause();
6866
}
6967

70-
// expose to the browser
71-
window.incrementTime = incrementTime;
72-
window.setAlarm = setAlarm;
73-
window.stopTimer = stopTimer;
68+
document.getElementById("up").addEventListener("click", () => incrementTime(5));
69+
document.getElementById("down").addEventListener("click", () => incrementTime(-5));
70+
document.getElementById("set").addEventListener("click", setAlarm);
71+
document.getElementById("stop").addEventListener("click", stopTimer);
7472

7573
// DO NOT EDIT BELOW HERE
7674
var audio = new Audio("alarmsound.mp3");

Sprint-3/alarmclock/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020
/>
2121

2222
<div class="increment-buttons">
23-
<button onclick="incrementTime(5)">▲ +5</button>
24-
<button onclick="incrementTime(-5)">▼ -5</button>
23+
<button id="up">▲ +5</button>
24+
<button id="down">▼ -5</button>
2525
</div>
2626

27-
<button class="set-button" onclick="setAlarm()">SET</button>
27+
<button id="set" class="set-button">SET</button>
2828

2929
<h1 id="timeRemaining" class="time-remaining">
3030
Time Remaining:<br />00:00
3131
</h1>
3232

33-
<button class="stop-button" onclick="stopTimer()">STOP</button>
33+
<button id="stop" class="stop-button">STOP</button>
3434
</div>
3535

3636
<script src="alarmclock.js"></script>

0 commit comments

Comments
 (0)