diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..4da0316
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,13 @@
+root = true
+
+[*]
+indent_style = space
+indent_size = 2
+trim_trailing_whitespace = true
+end_of_line = lf
+insert_final_newline = true
+
+[*.md]
+indent_size = 4
+trim_trailing_whitespace = false
+
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..2183d69
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,4 @@
+{
+ "angulardoc.repoId": "a547aa17-a9ab-4f77-ba4c-f3167ae617d2",
+ "angulardoc.lastSync": 0
+}
\ No newline at end of file
diff --git a/exercises/01 - JavaScript Drum Kit/README.md b/exercises/01 - JavaScript Drum Kit/README.md
index abe966a..5e39133 100644
--- a/exercises/01 - JavaScript Drum Kit/README.md
+++ b/exercises/01 - JavaScript Drum Kit/README.md
@@ -1,13 +1,13 @@
# Exercise 1: JavaScript Drum Kit
Nitish Dayal, Software & Applications Developer - [Contact](http://nitishdayal.me)
-Last Commit Date: Dec 9, 2016
+Last Commit Date: May 12, 2017
An HTML page displays a collection of `div` elements, each containing a letter
that corresponds with a key on the keyboard, and the name of the soundclip to be
played when that button is clicked. When a user presses a key that matches
- one of the `div` elements, the page should play the corresponding soundclip
- and place a temporary 'highlight' (or border) around the `div`. Write the
- JavaScript code necessary to add this functionality.
+ one of the letters displayed in the `div` elements, the page should play
+ the corresponding soundclip and place a temporary 'highlight' (or border)
+ around the `div`. Write the JavaScript code necessary to add this functionality.
## Guide
@@ -17,11 +17,11 @@ We are provided with the HTML, CSS, and sound clips necessary to create this
- HTML `data-*` attributes: Introduced in HTML5, `data-*` attributes (where * can
be anything you want) allow us to store _custom data_ on any HTML element. Each
- `div.key` and `audio` element in the provided HTML file has a `data-key` attribute
- which corresponds with a keyboard button.
+ `div.key` (`
`) and `audio` element in the
+ provided HTML file has a `data-key` attribute which corresponds with a keyboard button.
-- CSS `playing` class & pre-defined style: The provided CSS file already has an `playing`
- class defined with some styling in it. We will apply this class to the correct
+- CSS `playing` class & pre-defined style: The provided CSS file already has a `playing`
+ class defined with some rules in it. We will apply this class to the correct
element, depending on the key pressed by the user, and remove it once animation
is finished.
diff --git a/exercises/01 - JavaScript Drum Kit/index.html b/exercises/01 - JavaScript Drum Kit/index.html
index 38a4ee2..cc3c007 100644
--- a/exercises/01 - JavaScript Drum Kit/index.html
+++ b/exercises/01 - JavaScript Drum Kit/index.html
@@ -65,29 +65,46 @@
* the keypress, add a class to the specific element that matches with the keypress,
* and then remove that class in order to reset the element to it's original state.
*/
- function playSound(e) {
- const soundclip = document.querySelector(`audio[data-key="${e.keyCode}"]`);
- const keyelement = document.querySelector(`.key[data-key="${e.keyCode}"]`);
- if (!soundclip) return; // Stop function from running if key pressed doesn't match up with our elements
+ (()=> {
+ const playSound = (e) => {
+ const soundclip = document.querySelector(`audio[data-key="${e.keyCode}"]`);
+ const keyelement = document.querySelector(`.key[data-key="${e.keyCode}"]`);
- keyelement.classList.add('playing');
+ if (!soundclip) return undefined; // Stop function from running if key pressed doesn't match up with our elements
- soundclip.currentTime = 0; // Play sound clip from start every time a corresponding key is pressed
- soundclip.play();
- }
+ keyelement.classList.add('playing');
- function removeTransition(e) {
- if (e.propertyName !== 'transform') return; // skip if it's not a transform event
- this.classList.remove('playing');
- }
+ // Ensures that the sound clip always plays from the beginning. Otherwise,
+ // if the 'a' key is pressed twice rapidly, the soundclip will only play through
+ // once.
+ soundclip.currentTime = 0;
- const keys = document.querySelectorAll('.key'); // Find all elements in the document with a class 'key'
- keys.forEach(key => key.addEventListener('transitionend', removeTransition));
+ soundclip.play(); // Play sound
+ }
- window.addEventListener('keydown', playSound);
+ const removeTransition = (e) => {
+ // skip if it's not a transform event
+ if (e.propertyName !== 'transform') return undefined;
+ e.target.classList.remove('playing');
+ }
+
+ // Find all elements in the document with a class 'key'
+ const keys = document.querySelectorAll('.key');
+
+ // Listen for any `keydown` events that occur on this browser window instance (this page)
+ // When a `keydown` event is observered, trigger the `playSound` function, passing in the
+ // `keydown` event as the argument (e)
+ window.addEventListener('keydown', playSound);
+
+ keys.forEach(key =>
+ key.addEventListener(
+ 'transitionend',
+ (e) => removeTransition.call(key, e)
+ ));
+ })();