From 9c2f3355bc82aa8ad343b34f212f9bc869b8747f Mon Sep 17 00:00:00 2001 From: Kaitlin Forsman Date: Mon, 21 May 2018 16:43:58 -0700 Subject: [PATCH 1/2] sucessfully got the js event handlers to play sounds if the html button are clicked or if the corresponding keyboard letter is 'keydown' --- noise.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/noise.js b/noise.js index 1d6dd4b..f2b73a0 100644 --- a/noise.js +++ b/noise.js @@ -1,3 +1,12 @@ $(document).ready( function() { - // your code here + + $('.note').click( function(){ + const note = $( this ).attr("class").split(" ")[1]; + $(`#${note}Audio`)[0].play(); + }); + + $('body').keydown( function(event){ + $(`#${event.key}Audio`)[0].play(); + }); + }); From 10a7e1f8c53f9002aa9cb512938ae28429587361 Mon Sep 17 00:00:00 2001 From: Kaitlin Forsman Date: Mon, 21 May 2018 17:42:56 -0700 Subject: [PATCH 2/2] added .load to the logic so that you don't need to wait for the sound to finish playing before playing it again --- noise.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/noise.js b/noise.js index f2b73a0..cbc0495 100644 --- a/noise.js +++ b/noise.js @@ -2,10 +2,12 @@ $(document).ready( function() { $('.note').click( function(){ const note = $( this ).attr("class").split(" ")[1]; + $(`#${note}Audio`)[0].load(); $(`#${note}Audio`)[0].play(); }); $('body').keydown( function(event){ + $(`#${event.key}Audio`)[0].load(); $(`#${event.key}Audio`)[0].play(); });