Created
April 30, 2021 16:16
-
-
Save m4rk3r/865c99fdc0f2366430379802e32e6e4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let chords = { | |
'abc': 'audio/chord-1.mp3', | |
'def': 'audio/chord-2.mp3', | |
}; | |
// corresponding <div id="output"></div> | |
let output = document.querySelector('#output'); | |
// our input element | |
let input = document.querySelector('input'); | |
let audioChords = []; | |
function playChord(event) { | |
if (event.key == 'Enter') { | |
let ourText = input.value; | |
ourText.forEach((key) => { | |
let chord = Object.keys(chords).find(k => k.includes(key)); | |
if (chord) { | |
let audio = document.createElement('audio'); | |
audio.src = chords[chord]; | |
audio.play(); | |
audioChords.push(audio); | |
let img = document.createElement('img'); | |
img.src = `${chord}.png`; // abc.png | |
output.append(img); | |
} | |
}); | |
} | |
} | |
input.addEventListener('keyup', playChord); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment