Open your favorite IDE (I'm using VS Code Version 1.89.1) and create a folder for your HTML project. Create files with extensions: ".html", ".css" and ".js"
Write the HTML you want your page to look like using a simple background image using CSS and html. Create 7 image tag and attach drum images ("Kick, snare, tom 1,2,3,4"). Below you can see in my CSS file I have created a css element for each image and assigned a class selector for each.
In your HTML file (see below), I created a button tag for each image.
Each image also has 2 classes: "a key" and "drum". (See the CSS file for what these classes look like)
It's exactly what it sounds like! Here's the basic format:
addEventListener("click", displayDate);
By adding the above line of code AFTER whatever element or class or id or document tag you want,
you can trigger something to happen in your webpage: i.e. making a sound when someone click an image or button.
It can take 2 parameters, the first one being the event, and the second input is a function that does whatever you
want it to do.
One function called is makeSound and the other is ButtonAnimation. They both take a parameter called "ButtonInnerHTML" which is the corresponding key.
Below is a screenshot of both functions: It uses a switch function that compares one value to different cases. Based on the case, it will output an Audio object and play the sound file saved in your project folder.
A switch statement if used instead of multiple IF statements,
It takes one "expression", and compares it to "cases". You can have as many "cases" as you need
Based on which case it matches against, you can make it do "statements".
switch("expression"){
case "1": ( "statements" );
break;
case "2": ( "statements" );
break;
default:
}
Below is the second function that will output a sound based on a key press on
your keyboard. It basically adds a call using ".ClassListAdd" and applies a CSS Class
and then calls a delay function and then removed the class with ".ClassListRemove".
This flashes the button on and off when the keys are pressed.