Skip to content

Commit 4a95abf

Browse files
committed
feat: day 9
1 parent 05f4848 commit 4a95abf

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

009-sound board/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<audio src="sounds/tada.mp3" id="tada"></audio>
1414
<audio src="sounds/victory.mp3" id="victory"></audio>
1515
<audio src="sounds/wrong.mp3" id="wrong"></audio>
16+
<audio src="sounds/joke.mp3" id="joke"></audio>
1617
<div id="buttons"></div>
1718
<script src="script.js"></script>
1819
</body>

009-sound board/script.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const sounds = ["applause", "boo", "gasp", "tada", "victory", "wrong"];
1+
// Include a New Sound
2+
const sounds = ["applause", "boo", "gasp", "tada", "victory", "wrong", "joke"];
23
const buttons = document.getElementById("buttons");
34

45
const stopSounds = () => {
@@ -7,15 +8,25 @@ const stopSounds = () => {
78
currentSound.pause();
89
currentSound.currentTime = 0;
910
});
11+
document
12+
.querySelectorAll(".btn")
13+
.forEach((btn) => btn.classList.remove("playing"));
1014
};
1115

1216
sounds.forEach((sound) => {
1317
const btn = document.createElement("button");
1418
btn.classList.add("btn");
15-
btn.innerText = sound;
19+
// Change Button Text
20+
btn.innerText = btn.innerText = "Play " + sound.toUpperCase();
1621
btn.addEventListener("click", () => {
1722
stopSounds();
18-
document.getElementById(sound).play();
23+
// Add Visual Feedback on Play
24+
btn.classList.add("playing");
25+
const audio = document.getElementById(sound);
26+
audio.play();
27+
audio.onended = () => {
28+
btn.classList.remove("playing");
29+
};
1930
});
2031
buttons.appendChild(btn);
2132
});

009-sound board/sounds/joke.mp3

221 KB
Binary file not shown.

009-sound board/style.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ body {
1818
}
1919

2020
.btn {
21-
background-color: rebeccapurple;
22-
border-radius: 5px;
21+
/* Adjust Button Styling */
22+
background-color: #2e1c2b;
23+
color: #eaeaea;
24+
border-radius: 10px;
2325
border: none;
2426
color: #fff;
2527
margin: 1rem;
@@ -36,3 +38,7 @@ body {
3638
.btn:focus {
3739
outline: none;
3840
}
41+
42+
.btn.playing {
43+
background-color: rebeccapurple;
44+
}

0 commit comments

Comments
 (0)