Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<div id="drum-machine" >
  <h1>Drum Machine</h1>
 <div id='rows'>
  <div>
  <button class="drum-pad" id="kick" onmousedown="playQ()" onmouseup="resetMouse()">Q
    <audio class="clip" id="Q" src="http://www.burnkit2600.com/temp/HR-16/HR-16-WAVs/06-22%20dbl%20hd%20kick%20b.wav" type="audio/wav">
Your browser does not support the audio element.
</audio>
  </button>
  <button class="drum-pad" id="perc" onmousedown="playW()" onmouseup="resetMouse()">W
    <audio class="clip" id="W" src="http://www.synthmania.com/Boss%20DR-220A/Audio/Boss%20DR-220A%20WAV%20samples/Rim%20Shot.wav" type="audio/mp3">
Your browser does not support the audio element.
</audio>
  </button>
  <button class="drum-pad" id="clap" onmousedown="playE()" onmouseup="resetMouse()">E
    <audio class="clip" id="E" src="http://www.burnkit2600.com/temp/HR-16/HR-16-WAVs/47-hand%20claps.wav" type="audio/wav"> 
Your browser does not support the audio element.
</audio>
  </button>
  </div>
  <div>
  <button class="drum-pad" id="open-hat" onmousedown="playA()" onmouseup="resetMouse()">A
    <audio class="clip" id="A" src="http://www.burnkit2600.com/temp/HR-16/HR-16-WAVs/27-open%20hi%20hat.wav" type="audio/wav">
Your browser does not support the audio element.
</audio>
  </button>
  <button class="drum-pad" id="rim" onmousedown="playS()" onmouseup="resetMouse()">S
    <audio class="clip" id="S" src="http://www.synthmania.com/Roland%20D-50/Audio/Waveform%20demos/PCM%2033%20-%20Steam.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
  </button>
  <button class="drum-pad" id="chord-3" onmousedown="playD()" onmouseup="resetMouse()">D
    <audio class="clip" id="D" src="http://scruss.com/wordpress/wp-content/uploads/2017/12/chord-D.wav" type="audio/wav">
Your browser does not support the audio element.
</audio>
  </button>
  </div>
  <div>
  <button class="drum-pad" id="chord-1" onmousedown="playZ()" onmouseup="resetMouse()">Z
    <audio class="clip" id="Z" src="http://scruss.com/wordpress/wp-content/uploads/2017/12/chord-F.wav" type="audio/wav">
Your browser does not support the audio element.
</audio>
  </button>
  <button class="drum-pad" id="chord-2" onmousedown="playX()" onmouseup="resetMouse()">X
    <audio class="clip" id="X" src="http://scruss.com/wordpress/wp-content/uploads/2017/12/chord-E.wav" type="audio/wav">
Your browser does not support the audio element.
</audio>
  </button>
  <button class="drum-pad" id="shaker" onmousedown="playC()" onmouseup="resetMouse()">C
    <audio class="clip" id="C" src="http://www.utc.fr/si28/ProjetsUpload/P2006_si28p004/flash_puzzle/sons/rush/shaker.wav" type="audio/wav">
Your browser does not support the audio element.
</audio>
  </button>
   </div>
  <h1 id="display"></h1>
  </div>
</div>

              
            
!

CSS

              
                body {
  background-image: linear-gradient(red, yellow);
}
button {
  background-color: LightGrey;
  width: 6em;
  height: 5em;
  margin-bottom: 10px;
}
#rows {
  text-align: center;
  margin-top: 50px;
  margin-bottom: 70px
}
h1 {
  text-align: center;
}

#display {
  position: relative;
  border: solid blue 6px;
  width: 120px;
  padding-top: 15px;
  padding-bottom: 15px;
  background-color: blue;
  border-radius: 50%;
  margin: 0 auto;
  align: center;
  margin-top: 12px;
  color: yellow
}


              
            
!

JS

              
                document.getElementById("display").innerHTML = "[]"
function playQ() {
  let audio = document.getElementById("Q");
  audio.play();
  colorQ(); document.getElementById("display").innerHTML = "kick";
}  
function playW() {
  let audio = document.getElementById("W");
  audio.play();
  colorW();
  document.getElementById("display").innerHTML = "perc";
}  
function playE() {
  var audio = document.getElementById("E");
  audio.play();
  colorE();
  document.getElementById("display").innerHTML = "clap";
}  
function playA() {
  var audio = document.getElementById("A");
  audio.play();
  colorA();
  document.getElementById("display").innerHTML = "open-hat";
}  
function playS() {
  var audio = document.getElementById("S");
  audio.play();
  colorS();
  document.getElementById("display").innerHTML = "rim";
}  
function playD() {
  var audio = document.getElementById("D");
  audio.play();
  colorD();
  document.getElementById("display").innerHTML = "chord-3";
}  
function playZ() {
  var audio = document.getElementById("Z");
  audio.play();
  colorZ();
  document.getElementById("display").innerHTML = "chord-1";
}  
function playX() {
  var audio = document.getElementById("X");
  audio.play();
  colorX();
  document.getElementById("display").innerHTML = "chord-2";
}  
function playC() {
  var audio = document.getElementById("C");
  audio.play();
  colorC();
  document.getElementById("display").innerHTML = "shaker";
}  

function colorQ() { document.getElementById("kick").style.backgroundColor = "blue";
}

function colorW() { document.getElementById("perc").style.backgroundColor = "blue";
}

function colorE() { document.getElementById("clap").style.backgroundColor = "blue";
}

function colorA() { document.getElementById("open-hat").style.backgroundColor = "blue";
}

function colorS() { document.getElementById("rim").style.backgroundColor = "blue";
}

function colorD() { document.getElementById("chord-3").style.backgroundColor = "blue";
}

function colorZ() { document.getElementById("chord-1").style.backgroundColor = "blue";
}
function colorX() { document.getElementById("chord-2").style.backgroundColor = "blue";
}
function colorC() { document.getElementById("shaker").style.backgroundColor = "blue";
}

document.addEventListener('keydown', function(x) {
    switch(x.key) {
    case 'Q':
    case 'q':
      playQ();
      colorQ();
 document.getElementById("display").innerHTML = "kick";
      break;
    case 'W':
    case 'w':
      playW();
      colorW();
 document.getElementById("display").innerHTML = "perc";
      break;
    case 'E':
    case 'e':
      playE();
      colorE();
 document.getElementById("display").innerHTML = "clap";
      break;
    case 'A':
    case 'a':
      playA();
      colorA();
 document.getElementById("display").innerHTML = "open-hat";
      break;
    case 'S':
    case 's':
      playS();
      colorS();
 document.getElementById("display").innerHTML = "rim";
      break;
    case 'D': 
    case 'd':
      playD();
      colorD();
 document.getElementById("display").innerHTML = "chord-3";
      break;
    case 'Z':
    case 'z':
      playZ();
      colorZ();
 document.getElementById("display").innerHTML = "chord-1";
      break;
    case 'X':
    case 'x':
      playX();
      colorX();
 document.getElementById("display").innerHTML = "chord-2";
      break;
    case 'C':
    case 'c':
      playC();
      colorC(); document.getElementById("display").innerHTML = "shaker";
      break;
  }
});

document.addEventListener('keyup', function() {
 let keys = document.getElementsByClassName('drum-pad')
 for (let i = 0; i < keys.length; i++) {
 console.log(keys[i])
keys[i].style.backgroundColor = "LightGray";
 }
})  

const resetMouse = () => { let keys = document.getElementsByClassName('drum-pad')
 for (let i = 0; i < keys.length; i++) {
 console.log(keys[i])
keys[i].style.backgroundColor = "LightGray";
}
}


              
            
!
999px

Console