From 412362d9734d347a2e94a3c4b683f9e2ca9a5a55 Mon Sep 17 00:00:00 2001 From: enigmagnetic Date: Tue, 21 Nov 2017 08:24:40 -0800 Subject: [PATCH] Add click and key down events to play audio files. --- noise.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/noise.js b/noise.js index 1d6dd4b..4f90b10 100644 --- a/noise.js +++ b/noise.js @@ -1,3 +1,15 @@ $(document).ready( function() { - // your code here + $('.instrument button').click(function(event) { + let selector = $(this).html() + 'Audio'; + let audio = document.getElementById(selector); + audio.load(); + audio.play(); + }); + + $('body').keydown(function(event) { + let selector = event.key + 'Audio'; + let audio = document.getElementById(selector); + audio.load(); + audio.play(); + }); });