Skip to content

Commit 4a7def9

Browse files
Update script.js
1 parent c1de4b6 commit 4a7def9

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

29 - Countdown Timer/js/script.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"use strict";
2+
3+
const sound = document.getElementById("sound");
14
const buttons = document.querySelectorAll("[data-seconds]");
25
const form = document.querySelector("#form");
36
const input = document.querySelector("#input");
@@ -17,6 +20,9 @@ function timer(seconds) {
1720
clearInterval(countdown);
1821
return;
1922
}
23+
if (remainingTime.innerText === "00:00") {
24+
sound.pause();
25+
}
2026
displayRemainingTime(remainingSeconds);
2127
});
2228
}
@@ -43,36 +49,41 @@ function displayEndTime(then) {
4349
}
4450

4551
function startTimer1() {
52+
sound.play();
4653
const seconds = this.dataset.seconds;
4754
timer(seconds);
4855
}
4956

5057
function startTimer2(e) {
5158
e.preventDefault();
59+
sound.play();
5260
const minutes = input.value;
5361
const seconds = minutes * 60;
5462

5563
if (minutes / 1 != minutes) {
64+
sound.pause();
5665
clearInterval(countdown);
5766
remainingTime.textContent = "Please enter only numbers.";
58-
remainingTime.style.fontSize = "7rem";
67+
remainingTime.style.fontSize = window.innerWidth < 500 ? "4rem" : "7rem";
5968
document.title = "Countdown Timer";
6069
endTime.textContent = "";
6170
this.reset();
6271
return;
6372
}
6473

6574
if (minutes < 0) {
75+
sound.pause();
6676
clearInterval(countdown);
6777
remainingTime.textContent = "Please enter a positive number.";
68-
remainingTime.style.fontSize = "7rem";
78+
remainingTime.style.fontSize = window.innerWidth < 500 ? "3.9rem" : "7rem";
6979
document.title = "Countdown Timer";
7080
endTime.textContent = "";
7181
this.reset();
7282
return;
7383
}
7484

7585
if (minutes == 0) {
86+
sound.pause();
7687
clearInterval(countdown);
7788
remainingTime.textContent = "Oh, no! Zero?";
7889
remainingTime.style.fontSize = "7rem";

0 commit comments

Comments
 (0)