From cdeb5ade2e77d9f1c96e9c6bd91200a328f111bd Mon Sep 17 00:00:00 2001 From: Laura Robertson Date: Mon, 20 Nov 2017 19:45:34 -0800 Subject: [PATCH 1/5] Sounds play when a user clicks on a button or uses a keyboard key --- noise.css | 6 +++++- noise.js | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/noise.css b/noise.css index 5c37256..bf5c812 100644 --- a/noise.css +++ b/noise.css @@ -3,7 +3,7 @@ html { } body { - background-color: black; + background-color: black; } .instrument { @@ -51,3 +51,7 @@ body { .b { color: #f26fd4; background-color: #43293d; } .b:hover { background-color: #6f3a62; } .b:active, .b.active { background-color: #f26fd4; } + +.yellow { + border: 10px solid yellow; +} diff --git a/noise.js b/noise.js index 1d6dd4b..ad761ef 100644 --- a/noise.js +++ b/noise.js @@ -1,3 +1,21 @@ -$(document).ready( function() { - // your code here +//* eslint-disable */ + +$(document).ready(() => { + const notes = ['a', 'b', 'c', 'd', 'e', 'f', 'g']; + + const play = (sound) => { + const note = `#${sound}Audio`; + $(note).get(0).load(); + $(note).get(0).play(); + }; + + $('.note').click(function click() { + play($(this).html()); + }); + + $('body').keydown((event) => { + if (notes.includes(event.key)) { + play(event.key); + } + }); }); From 01382392fca3a7712c448d6923a25d55b837bb96 Mon Sep 17 00:00:00 2001 From: Laura Robertson Date: Mon, 20 Nov 2017 20:07:22 -0800 Subject: [PATCH 2/5] Refactored to use .on --- noise.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/noise.js b/noise.js index ad761ef..cb98947 100644 --- a/noise.js +++ b/noise.js @@ -1,20 +1,16 @@ -//* eslint-disable */ - $(document).ready(() => { const notes = ['a', 'b', 'c', 'd', 'e', 'f', 'g']; - const play = (sound) => { - const note = `#${sound}Audio`; + const play = (letter) => { + const note = `#${letter}Audio`; $(note).get(0).load(); $(note).get(0).play(); }; - $('.note').click(function click() { - play($(this).html()); - }); - - $('body').keydown((event) => { - if (notes.includes(event.key)) { + $('.note, body').on('click keydown', function player(event) { + if (event.type === 'click') { + play($(this).html()); + } else if (event.type === 'keydown' && notes.includes(event.key)) { play(event.key); } }); From 38cb459f1b9c457c558687122dd958d856e937c3 Mon Sep 17 00:00:00 2001 From: Laura Robertson Date: Mon, 20 Nov 2017 20:10:28 -0800 Subject: [PATCH 3/5] Removed test class --- noise.css | 4 ---- 1 file changed, 4 deletions(-) diff --git a/noise.css b/noise.css index bf5c812..527e0ec 100644 --- a/noise.css +++ b/noise.css @@ -51,7 +51,3 @@ body { .b { color: #f26fd4; background-color: #43293d; } .b:hover { background-color: #6f3a62; } .b:active, .b.active { background-color: #f26fd4; } - -.yellow { - border: 10px solid yellow; -} From 8d10c629eb43b5871f62bf56a7cace3b6781390e Mon Sep 17 00:00:00 2001 From: Laura Robertson Date: Mon, 20 Nov 2017 20:34:26 -0800 Subject: [PATCH 4/5] Removed comparison keys --- noise.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/noise.js b/noise.js index cb98947..1fdf704 100644 --- a/noise.js +++ b/noise.js @@ -1,16 +1,14 @@ $(document).ready(() => { - const notes = ['a', 'b', 'c', 'd', 'e', 'f', 'g']; - const play = (letter) => { - const note = `#${letter}Audio`; - $(note).get(0).load(); - $(note).get(0).play(); + const note = $(`#${letter}Audio`).get(0); + note.load(); + note.play(); }; $('.note, body').on('click keydown', function player(event) { if (event.type === 'click') { play($(this).html()); - } else if (event.type === 'keydown' && notes.includes(event.key)) { + } else if (event.type === 'keydown') { play(event.key); } }); From 3c3108ac32c63e8f0e490b1a562dcd7d56bde2eb Mon Sep 17 00:00:00 2001 From: Laura Robertson Date: Mon, 20 Nov 2017 21:00:33 -0800 Subject: [PATCH 5/5] Added conditional to replace previous array --- noise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noise.js b/noise.js index 1fdf704..979db5e 100644 --- a/noise.js +++ b/noise.js @@ -8,7 +8,7 @@ $(document).ready(() => { $('.note, body').on('click keydown', function player(event) { if (event.type === 'click') { play($(this).html()); - } else if (event.type === 'keydown') { + } else if (event.type === 'keydown' && event.keyCode > 64 && event.keyCode < 72) { play(event.key); } });