Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions 01 - JavaScript Drum Kit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 🥁 JavaScript Drum Kit

A fun interactive drum kit built with vanilla JavaScript. Press keys on your keyboard or click the buttons to play drum sounds!

## Features

- 🎹 **9 Drum Sounds** - Clap, Hi-hat, Kick, Openhat, Boom, Ride, Snare, Tom, and Tink
- ⌨️ **Keyboard Support** - Press A, S, D, F, G, H, J, K, L to play sounds
- 📱 **Mobile Friendly** - Click/tap buttons to play on touch devices
- ✨ **Visual Feedback** - Keys animate when played
- 🔄 **Rapid Fire** - Play multiple sounds simultaneously

## How to Use

1. Open `index-FINISHED.html` in your web browser
2. **Press keyboard keys A through L** to play different drum sounds:
- **A** - Clap
- **S** - Hi-hat
- **D** - Kick
- **F** - Open Hat
- **G** - Boom
- **H** - Ride
- **J** - Snare
- **K** - Tom
- **L** - Tink

3. Or **click/tap the drum pads** directly on the screen

## Project Structure

```
├── index-FINISHED.html # Main HTML file
├── style.css # Styling and animations
├── sounds/ # Audio files folder
│ ├── clap.wav
│ ├── hihat.wav
│ ├── kick.wav
│ ├── openhat.wav
│ ├── boom.wav
│ ├── ride.wav
│ ├── snare.wav
│ ├── tom.wav
│ └── tink.wav
└── README.md # This file
```

## Technologies Used

- **HTML5** - Audio elements and structure
- **CSS3** - Styling and key animations
- **Vanilla JavaScript** - Event handling and audio playback

## Browser Support

Works on all modern browsers that support:
- HTML5 Audio API
- ES6 JavaScript
- CSS3 Transforms

## Notes

- Sounds play with visual feedback (key scale animation)
- Multiple keys can be pressed simultaneously
- Audio resets on each keystroke for rapid playback

Enjoy making beats! 🎵
30 changes: 25 additions & 5 deletions 01 - JavaScript Drum Kit/index-FINISHED.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,44 @@
<audio data-key="76" src="sounds/tink.wav"></audio>

<script>
// Map of key names to their corresponding key codes
const keyMap = {
'a': 65, 's': 83, 'd': 68, 'f': 70, 'g': 71,
'h': 72, 'j': 74, 'k': 75, 'l': 76
};

function removeTransition(e) {
if (e.propertyName !== 'transform') return;
e.target.classList.remove('playing');
}

function playSound(e) {
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
const key = document.querySelector(`div[data-key="${e.keyCode}"]`);
function playSound(keyCode) {
const audio = document.querySelector(`audio[data-key="${keyCode}"]`);
const key = document.querySelector(`div[data-key="${keyCode}"]`);
if (!audio) return;

key.classList.add('playing');
audio.currentTime = 0;
audio.play();
}

// Handle keyboard events with modern e.key support
function handleKeydown(e) {
const keyCode = e.keyCode || keyMap[e.key?.toLowerCase()];
if (keyCode) {
playSound(keyCode);
}
}

const keys = Array.from(document.querySelectorAll('.key'));
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
window.addEventListener('keydown', playSound);
keys.forEach(key => {
key.addEventListener('transitionend', removeTransition);
// Add click/tap support for mobile
key.addEventListener('click', () => {
playSound(key.dataset.key);
});
});
window.addEventListener('keydown', handleKeydown);
</script>


Expand Down