Skip to content

Commit 5a5f3b0

Browse files
committed
some comments
1 parent 51b9804 commit 5a5f3b0

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// make the sound happen by using `playAlarm()`.
1010
// You can stop the alarm sound by pressing the `Stop Alarm` button.
1111

12-
const alarmInputArea = document.querySelector("#alarmSet");
12+
const alarmInputArea = document.querySelector("#alarmSet"); // get access to InputArea
1313
console.log(alarmInputArea, "<---- InputArea");
1414

1515
const setAlarmButton = document.querySelector("#set");
@@ -24,64 +24,65 @@ console.log(timeRemainInfo, "<------Remain Time");
2424
const backgroundColor = document.querySelector("html");
2525
console.log(backgroundColor, "<------Background Color");
2626

27-
let intervalId;
28-
let inputInfo = 0;
27+
let intervalId; // declare variable
28+
let inputInfo = 0; // declare 'inputInfo' as an 'intervalId' global
2929

3030
function timeFormat(time) {
31+
// revert number into min and sec format function
3132
const mins = String(Math.floor(time / 60)).padStart(2, "0");
3233
const seconds = String(time % 60).padStart(2, "0");
3334
timeRemainInfo.textContent = `Time Remaining: ${mins}:${seconds}`;
3435
}
3536

3637
function setAlarm() {
37-
inputInfo = Number(alarmInputArea.value);
38+
inputInfo = Number(alarmInputArea.value); // convert input into number
3839
if (inputInfo < 1 || isNaN(inputInfo)) {
40+
// to sift invalid input
3941
console.log("You need to input a value in seconds!");
4042
window.alert("You need to input a value in seconds!");
4143
return;
4244
}
43-
alarmInputArea.value = "";
44-
timeFormat(inputInfo);
45+
alarmInputArea.value = ""; // clean input area when data assigned to 'inputInfo'
46+
timeFormat(inputInfo); // set format input to min and sec
4547

4648
intervalId = setInterval(function () {
47-
inputInfo--;
49+
//function to set interval for
50+
inputInfo--; // countdown the input by 1 sec by iterat.
4851
if (inputInfo === 0) {
52+
// if input equal 0, set alarm signal and flashing
4953
clearInterval(intervalId);
5054
timeFormat(0);
5155
window.playAlarm();
5256
changeBackgroundColorFlashing();
5357
} else {
58+
// if input not equal 0, just continue count down
5459
timeFormat(inputInfo);
5560
}
5661
}, 1000);
5762
}
5863

59-
//setAlarmButton.addEventListener("click", function setAlarm() {
60-
//console.log("click event is firing...");
61-
//});
62-
let flashColor = ["yellow", "pink", "lightgrey", "green"];
63-
let flashIntervalId;
64+
let flashColor = ["yellow", "pink", "lightgrey", "green"]; // array for flashing
65+
let flashIntervalId; // declaring globally variable
6466
let colorIndex = 0;
6567

6668
setStopButton.addEventListener("click", function stopFlashing() {
6769
console.log("click event is firing...");
68-
clearInterval(flashIntervalId);
69-
backgroundColor.style.backgroundColor = "";
70+
clearInterval(flashIntervalId); // cleaning any previous possible intervals
71+
backgroundColor.style.backgroundColor = ""; // cleaning background to default
72+
// option after clicking stop button
7073
window.pauseAlarm();
7174
});
7275

73-
//function changeBackgroundColor() {
74-
//backgroundColor.style.backgroundColor = "lightblue";
75-
//}
76-
7776
function changeBackgroundColorFlashing() {
78-
if (flashIntervalId) clearInterval(flashIntervalId);
77+
//function flashing colors
78+
if (flashIntervalId) clearInterval(flashIntervalId); // every 1 sec
7979
flashIntervalId = setInterval(function () {
8080
backgroundColor.style.backgroundColor = flashColor[colorIndex];
81-
colorIndex = (colorIndex + 1) % flashColor.length;
81+
colorIndex = (colorIndex + 1) % flashColor.length; // loop over flashColor array
8282
}, 1000);
83-
//stopFlashing();
83+
//stopFlashing(); //setTimeout(() => clearInterval(flashIntervalId), 1000);
8484
}
85+
8586
window.playAlarm = playAlarm;
8687
window.pauseAlarm = pauseAlarm;
8788

0 commit comments

Comments
 (0)