I work on a script that intercepts pressing the buttons of the keyboard and instead of their values displays the desired images on the screen. Tell me, please, how can I make the output of each image accompanied by the playback of a certain corresponding sound file? Those. I click, for example, on "Q", I see a picture on the screen and at the same time I hear a sound on the background, then I press W, I see another picture and another sound? Add. libraries would not like to use, if possible, only pure JS.
PS This is necessary for scientific work, and not for the terror of users of any site with different sounds :) I spent several hours in Google, but since I am not well versed in this topic, I could not adapt the existing examples to fit my case Help me please!
function keyEvent(){ var imgSrc = null; var container = document.getElementById( 'storage' ); switch(event.keyCode){ case 81: { imgSrc="http://posudoria.ru/parlament/2.jpg"; break; } // "Q" case 87: { imgSrc="http://posudoria.ru/parlament/3.jpg"; break; } // "W" case 69: { imgSrc="http://posudoria.ru/parlament/4.jpg"; break; } // "E" case 82: { imgSrc="http://posudoria.ru/parlament/5.jpg"; break; } // "R" case 84: { imgSrc="http://posudoria.ru/parlament/6.jpg"; break; } // "T" case 89: { imgSrc="http://posudoria.ru/parlament/7.jpg"; break; } // "Y" case 13: { if (container.lastElementChild.childElementCount) { var line = document.createElement("div"); line.className = 'line'; container.appendChild( line ); } break; } case 8: { event.preventDefault(); if(container.childElementCount) { if (!container.lastElementChild.childElementCount) { container.removeChild(container.lastElementChild); } container.lastElementChild.removeChild(container.lastElementChild.lastElementChild); } } } if( imgSrc == null ) return; var img = document.createElement('img'), div = document.createElement('div'); img.setAttribute("src", imgSrc); div.className = 'container'; div.appendChild( img ); if (!container.childElementCount) { var line = document.createElement("div"); line.className = 'line'; container.appendChild(line); } container.lastElementChild.appendChild( div ); } document.body.onkeydown = keyEvent;