Skip to content

Commit d22ceda

Browse files
committed
Solving 01
1 parent 38a754c commit d22ceda

File tree

3 files changed

+73
-5
lines changed

3 files changed

+73
-5
lines changed

01 - JavaScript Drum Kit/index-START.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
<kbd>L</kbd>
4646
<span class="sound">tink</span>
4747
</div>
48+
4849
</div>
50+
<h1 class="text"> Your Score: <span id="score"> 0 </span> </h1>
51+
4952

5053
<audio data-key="65" src="sounds/clap.wav"></audio>
5154
<audio data-key="83" src="sounds/hihat.wav"></audio>
@@ -57,9 +60,7 @@
5760
<audio data-key="75" src="sounds/tom.wav"></audio>
5861
<audio data-key="76" src="sounds/tink.wav"></audio>
5962

60-
<script>
61-
62-
</script>
63+
<script src="javaScript.js"></script>
6364

6465

6566
</body>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const keys = [
2+
"65",
3+
"83",
4+
"68",
5+
"70",
6+
"71",
7+
"72",
8+
"74",
9+
"75",
10+
"76"
11+
];
12+
let score = 0 ;
13+
function sound(e){
14+
console.log(e.keyCode);
15+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
16+
const button = document.querySelector(`div[data-key="${e.keyCode}"]`);
17+
18+
if(!audio) return;
19+
if(button.classList.contains('click')){
20+
document.getElementById('score').innerHTML= ++score;
21+
}
22+
button.classList.add('playing');
23+
audio.currentTime=0;
24+
audio.play();
25+
26+
27+
}
28+
29+
function effect(button){
30+
button.addEventListener('transitionend', e =>
31+
{
32+
if(e.propertyName==="transform")
33+
button.classList.remove('playing');
34+
button.classList.remove('click');
35+
36+
}
37+
)}
38+
39+
function randomKey(preKey=65){
40+
const random = Math.floor((Math.random())*9);
41+
const key = keys.filter((_,index) => random == index);
42+
document.querySelector(`div[data-key="${key}"]`).classList.add('click');
43+
44+
setTimeout(_=>randomKey(key),1000);
45+
}
46+
window.addEventListener('keydown', sound);
47+
document.querySelectorAll('.key').forEach(effect);
48+
49+
setTimeout(randomKey,1000);

01 - JavaScript Drum Kit/style.css

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ body,html {
2323
margin:1rem;
2424
font-size: 1.5rem;
2525
padding:1rem .5rem;
26-
transition:all .07s;
26+
transition:all 1s;
2727
width:100px;
2828
text-align: center;
2929
color:white;
@@ -35,16 +35,34 @@ body,html {
3535
transform:scale(1.1);
3636
border-color:#ffc600;
3737
box-shadow: 0 0 10px #ffc600;
38+
color:#ffc600;
39+
3840
}
41+
.click {
42+
border-color:red;
43+
box-shadow: 0 0 10p red;
44+
color:red;
45+
3946

47+
}
4048
kbd {
4149
display: block;
4250
font-size: 40px;
4351
}
44-
52+
.text {
53+
display: block;
54+
font-size: 40px;
55+
color:white;
56+
}
4557
.sound {
4658
font-size: 1.2rem;
4759
text-transform: uppercase;
4860
letter-spacing: 1px;
4961
color:#ffc600;
5062
}
63+
64+
#score{
65+
font-size: 5rem;
66+
color:#ffc600;
67+
68+
}

0 commit comments

Comments
 (0)