Skip to content

Commit b6af9d4

Browse files
committed
formatted it
1 parent 76f1971 commit b6af9d4

File tree

2 files changed

+38
-48
lines changed

2 files changed

+38
-48
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
2-
3-
4-
51
let timeLeft = 0;
62
let timer = null;
73
let flashing = null;
84

95
// DOM references
106
window.addEventListener("DOMContentLoaded", () => {
7+
const stopButton = document.getElementById("stop");
118

12-
const stopButton = document.getElementById("stop");
13-
14-
// Event listeners
9+
// Event listeners
1510

16-
if (stopButton) stopButton.addEventListener("click", stopAlarm);
11+
if (stopButton) stopButton.addEventListener("click", stopAlarm);
1712

18-
// Show 00:00 on load
19-
updateDisplay(0);
13+
// Show 00:00 on load
14+
updateDisplay(0);
2015
});
2116

2217
// -------------------------------
@@ -25,21 +20,21 @@ updateDisplay(0);
2520

2621
function setAlarm() {
2722
const inputEl = document.getElementById("alarmSet");
28-
const input = inputEl.value.trim();
23+
const input = inputEl.value.trim();
2924

30-
// Check empty input
31-
if (input === "") {
32-
alert("Please enter a number of seconds.");
33-
return;
34-
}
25+
// Check empty input
26+
if (input === "") {
27+
alert("Please enter a number of seconds.");
28+
return;
29+
}
3530

36-
const parsed = parseInt(input, 10);
31+
const parsed = parseInt(input, 10);
3732

38-
// Check invalid or negative number
39-
if (isNaN(parsed) || parsed < 0) {
40-
alert("Please enter a valid non-negative number.");
41-
return;
42-
}
33+
// Check invalid or negative number
34+
if (isNaN(parsed) || parsed < 0) {
35+
alert("Please enter a valid non-negative number.");
36+
return;
37+
}
4338

4439
timeLeft = parsed;
4540

@@ -48,59 +43,56 @@ if (isNaN(parsed) || parsed < 0) {
4843

4944
// Clear previous countdown
5045
clearInterval(timer);
51-
clearInterval(flashing); // stop flashing if it was active
46+
clearInterval(flashing); // stop flashing if it was active
5247
flashing = null;
5348
document.body.style.backgroundColor = "";
54-
pauseAlarm(); // stop any playing audio
49+
pauseAlarm(); // stop any playing audio
5550
audio.currentTime = 0;
5651

5752
function tick() {
58-
if (timeLeft > 0) {
59-
timeLeft--;
60-
updateDisplay(timeLeft);
61-
} else {
62-
clearInterval(timer);
63-
startAlarm();
53+
if (timeLeft > 0) {
54+
timeLeft--;
55+
updateDisplay(timeLeft);
56+
} else {
57+
clearInterval(timer);
58+
startAlarm();
59+
}
6460
}
65-
}
6661

67-
// Run once immediately for consistency
68-
tick();
69-
timer = setInterval(tick, 1000);
62+
// Run once immediately for consistency
63+
tick();
64+
timer = setInterval(tick, 1000);
7065
}
7166

7267
function updateDisplay(seconds) {
7368
const mins = String(Math.floor(seconds / 60)).padStart(2, "0");
7469
const secs = String(seconds % 60).padStart(2, "0");
75-
70+
7671
const display = document.getElementById("timeRemaining");
77-
if (!display) return;
72+
if (!display) return;
7873
display.textContent = `Time Remaining: ${mins}:${secs}`;
7974
}
8075

8176
function startAlarm() {
8277
playAlarm();
8378

8479
// Flashing background
85-
if (!flashing){
80+
if (!flashing) {
8681
flashing = setTimeout(() => {
87-
document.body.style.backgroundColor =
88-
document.body.style.backgroundColor === "red" ? "orange" : "red";
89-
}, 300);
90-
}
82+
document.body.style.backgroundColor =
83+
document.body.style.backgroundColor === "red" ? "orange" : "red";
84+
}, 300);
85+
}
9186
}
9287

9388
function stopAlarm() {
94-
9589
clearInterval(flashing);
9690
flashing = null;
9791
document.body.style.backgroundColor = "";
9892
}
9993

100-
10194
// module.exports= setAlarm;
10295

103-
10496
// DO NOT EDIT BELOW HERE
10597

10698
var audio = new Audio("alarmsound.mp3");
@@ -121,6 +113,6 @@ function playAlarm() {
121113

122114
function pauseAlarm() {
123115
audio.pause();
124-
}
116+
}
125117

126118
window.onload = setup;

Sprint-3/alarmclock/alarmclock.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ afterEach(() => {
3737
page = null;
3838
});
3939

40-
41-
4240
test("should set heading when button is clicked", () => {
4341
const heading = page.window.document.querySelector("#timeRemaining");
4442
const input = page.window.document.querySelector("#alarmSet");
@@ -103,6 +101,6 @@ test("should play audio when the timer reaches zero", () => {
103101
expect(mockPlayAlarm).toHaveBeenCalledTimes(0);
104102

105103
jest.runAllTimers();
106-
104+
107105
expect(mockPlayAlarm).toHaveBeenCalledTimes(1);
108106
});

0 commit comments

Comments
 (0)