My approach on the Drum Kit : day 1 #691
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
INTRODUCTION
Well setting up the drum kit was quite easy. I had created a set of buttons that consisted the specific sound effect names so that users can guide through and work on it easily.
THE MAIN IMPLEMENTATION
When it came to implementing and getting the desired sound, i tackled the approach in a different way. Frankly, I did not refer to the video since I wanted to give it my own shot and if I get stuck of course there is the video solution to help me figure out.
Coming to the point, the first thing to tackle was to generate the music. The sound effect. To do that, I used the normal Audio constructor that is a pretty handy tool by JavaScript that lets you play music.
Well, that's how I began. The next task was on how to generate these sound effects. For that, I have used buttons that have the text based on the sound effect they produce so that it would be easy for the users to navigate and also get an idea on what is the sound effect. So for each button I inserted the text value as the name of the sound effect and I applied a "for each loop". Also I used a
document.querySelectorAll('button')
functionality giving it a variablenotes
so that I can access my for each loop. Pretty conveniently I used the for each loop that iterates over each of the buttons and if thebutton.taextContent == "sound-effect"
Then that particular sound effect would be played. Now similarly this must happen When I press keys on my keyboard. I used akeypress
event listener and ifval.key == 'sound-effect-key'
then it would play that particular sound effect. Well this was my approach and I got pretty much things done in an easier way, rather than beauti-fying all the stuff.