From 1a3a5aa2cc665aae975a92a8bead1fae54686dd6 Mon Sep 17 00:00:00 2001 From: Phoebe Date: Tue, 22 May 2018 08:57:48 -0700 Subject: [PATCH] has keys and click events --- noise.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/noise.js b/noise.js index 1d6dd4b..aec34dd 100644 --- a/noise.js +++ b/noise.js @@ -1,3 +1,15 @@ $(document).ready( function() { - // your code here + $('div.instrument').on('click', 'button', function(){ + console.log($(this).html()); + $( '#'+$(this).html()+'Audio' ).get(0).play(); + }); + + let keyBindings = { 67:'c', 68:'d', 69:'e', 70:'f', 71:'g', 65:'a', 66:'b' } + + $('body').keydown( function(event){ + if ( Object.keys(keyBindings).includes( event.keyCode.toString() ) ){ + $( '#' + keyBindings[event.keyCode] + 'Audio' ).get(0).play(); + } + }); + });