Skip to content

Commit 87feaaf

Browse files
authored
v01.1
1 parent 5f975b0 commit 87feaaf

10 files changed

Lines changed: 185 additions & 0 deletions

File tree

the-sound-quiz/1.mp3

115 KB
Binary file not shown.

the-sound-quiz/2.mp3

639 KB
Binary file not shown.

the-sound-quiz/3.mp3

83 KB
Binary file not shown.

the-sound-quiz/4.mp3

21.2 KB
Binary file not shown.

the-sound-quiz/5.mp3

6.69 MB
Binary file not shown.

the-sound-quiz/LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2025, hellenicdev
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

the-sound-quiz/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a sound quiz. Have fun :)

the-sound-quiz/index.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Sound Quiz</title>
6+
<link rel="stylesheet" href="style.css">
7+
</head>
8+
<body>
9+
10+
<h1>🔊 Sound Quiz</h1>
11+
12+
<div id="quiz">
13+
<button id="playButton" onclick="playSound()">Play Sound</button>
14+
15+
<div class="question" id="question" style="display:none;">
16+
<p>What sound was that?</p>
17+
<input type="text" id="userGuess" placeholder="Type your guess..." />
18+
<button onclick="submitAnswer()">Submit</button>
19+
</div>
20+
21+
<div id="result"></div>
22+
</div>
23+
24+
<div id="credits" style="display:none;">
25+
<h2>🎉 Quiz Completed!</h2>
26+
<h3>CREDITS:</h3>
27+
<p>Sound 1: freesound_community</p>
28+
<p>Sound 2: AstonMartinVantageV12</p>
29+
<p>Sound 3: freesound_community</p>
30+
<p>Sound 4: Rikeromega3 Productions</p>
31+
<p>Sound 5: murzik.net</p>
32+
</div>
33+
34+
<!-- Audio elements -->
35+
<audio id="1" src="1.mp3"></audio>
36+
<audio id="2" src="2.mp3"></audio>
37+
<audio id="3" src="3.mp3"></audio>
38+
<audio id="4" src="4.mp3"></audio>
39+
<audio id="5" src="5.mp3"></audio>
40+
41+
<script src="script.js"></script>
42+
</body>
43+
</html>

the-sound-quiz/script.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
const soundAnswers = {
2+
'1': ['ship', 'boat'],
3+
'2': ['car'],
4+
'3': ['bird'],
5+
'4': ['starwars', 'star wars'],
6+
'5': ['espressomachiatto', 'espresso machiatto']
7+
};
8+
9+
let currentSound = '';
10+
let usedSounds = [];
11+
12+
function playSound() {
13+
// Disable play button until next round
14+
document.getElementById('playButton').disabled = true;
15+
document.getElementById('userGuess').addEventListener('keydown', function(event) {
16+
if (event.key === 'Enter') {
17+
submitAnswer();
18+
}
19+
});
20+
21+
22+
// All sounds played? Show credits
23+
if (usedSounds.length === 5) {
24+
document.getElementById('quiz').style.display = 'none';
25+
document.getElementById('credits').style.display = 'block';
26+
return;
27+
}
28+
29+
// Pick a random unused sound
30+
let sound;
31+
do {
32+
sound = String(Math.floor(Math.random() * 5) + 1);
33+
} while (usedSounds.includes(sound));
34+
usedSounds.push(sound);
35+
currentSound = sound;
36+
37+
// Play the sound
38+
const audio = document.getElementById(currentSound);
39+
audio.play();
40+
41+
// Show input area
42+
document.getElementById('userGuess').value = '';
43+
document.getElementById('question').style.display = 'block';
44+
document.getElementById('result').textContent = '';
45+
document.getElementById('userGuess').focus();
46+
}
47+
48+
function submitAnswer() {
49+
const guess = document.getElementById('userGuess').value.trim().toLowerCase();
50+
51+
const validAnswers = soundAnswers[currentSound] || [];
52+
const normalizedAnswers = validAnswers.map(a => a.toLowerCase());
53+
54+
// Stop and reset the audio
55+
const audio = document.getElementById(currentSound);
56+
audio.pause();
57+
audio.currentTime = 0;
58+
59+
const result = document.getElementById('result');
60+
if (normalizedAnswers.includes(guess)) {
61+
result.textContent = '✅ Correct!';
62+
result.style.color = 'green';
63+
} else {
64+
result.textContent = '❌ Incorrect!';
65+
result.style.color = 'red';
66+
}
67+
68+
// Wait before allowing the next round
69+
setTimeout(() => {
70+
document.getElementById('question').style.display = 'none';
71+
document.getElementById('result').textContent = '';
72+
document.getElementById('playButton').disabled = false;
73+
74+
if (usedSounds.length === 5) {
75+
document.getElementById('quiz').style.display = 'none';
76+
document.getElementById('credits').style.display = 'block';
77+
}
78+
}, 1500);
79+
}

the-sound-quiz/style.css

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
body {
2+
font-family: Arial, sans-serif;
3+
text-align: center;
4+
margin-top: 50px;
5+
background-color: #f8f9fa;
6+
}
7+
8+
button {
9+
padding: 10px 20px;
10+
font-size: 16px;
11+
margin: 10px 5px;
12+
cursor: pointer;
13+
}
14+
15+
input[type="text"] {
16+
padding: 10px;
17+
font-size: 16px;
18+
width: 250px;
19+
}
20+
21+
#result {
22+
margin-top: 20px;
23+
font-size: 20px;
24+
font-weight: bold;
25+
}
26+
27+
.question {
28+
margin-top: 20px;
29+
}
30+
31+
#credits {
32+
margin-top: 40px;
33+
font-size: 18px;
34+
}

0 commit comments

Comments
 (0)