-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
53 lines (41 loc) · 1.08 KB
/
Copy pathscript.js
File metadata and controls
53 lines (41 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const removeBtnEl = document.getElementById("remove-btn");
const countTextEl = document.getElementById("count-text");
const addBtnEl = document.getElementById("add-btn");
const deleteBtnEl = document.getElementById("reset-btn");
const addSound = new Audio("assets/sounds/start.mp3");
const removeSound = new Audio("assets/sounds/Pop.mp3");
//Sound
addSound.preload = "auto";
removeSound.preload = "auto";
addSound.volume = 0.5;
removeSound.volume = 0.5;
function playSound(sound) {
sound.currentTime = 0;
sound.play().catch(() => {
console.error("Audio failed to play", error);
});
}
let count = 0;
function render() {
countTextEl.textContent = String(count);
}
function increment() {
count += 1;
render();
playSound(addSound);
}
function decrement() {
if(count > 0) {
count -= 1;
render();
playSound(removeSound);
}
}
function resetCount() {
count = 0;
render();
}
addBtnEl.addEventListener('click', increment);
removeBtnEl.addEventListener('click', decrement);
deleteBtnEl.addEventListener('click', resetCount);
render();