From 3fe1dc10cdb4fae36f88aa71de3691138798f7e6 Mon Sep 17 00:00:00 2001 From: laurenfb Date: Mon, 21 Nov 2016 14:54:28 -0800 Subject: [PATCH] wave 1 & 2 --- noise.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/noise.js b/noise.js index 1d6dd4b..4ae98a3 100644 --- a/noise.js +++ b/noise.js @@ -1,3 +1,33 @@ $(document).ready( function() { // your code here + + var notes = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g'] + + var stop = function(note) { + // stolen from jeannie who stole it from the internet + var song = document.getElementById(note + 'Audio'); + song.removeAttribute("src"); + song.load(); + } + + var playNoteClick = function(note) { + $('.' + note).click( function() { + stop(note); + document.getElementById(note + 'Audio').play(); + }); + } + + var playNoteKeyPress = function(note) { + $('body').keydown( function(event) { + stop(note); + if (event.key == note) { + document.getElementById(note + 'Audio').play(); + }; + }); + } + + for (var i = 0; i < notes.length; i++) { + playNoteClick(notes[i]); + playNoteKeyPress(notes[i]) + }; });