css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<h1>La plej mojosa tamburmaŝino ;-)</h1>
<div id="app"></div>

              body {
    background-color: beige;

h1 {
  text-transform: uppercase;
  font-weight: bold;
  font-size: 0.8em;
  text-align: right;

#drum-machine {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

#display {
  box-shadow: inset 2px 2px 2px 2px black;
  width: 95%;
  border: 1px solid black;
  border-radius: 3px;
  padding: 20px;
  margin: 20px;
  text-align: center;
  font-size: 1.2em;
  font-family: 'Share Tech Mono', monospace;
  background-color: rgb(25, 100, 70);
  color: yellow;

.drum-pad {
  width: 70px;
  height: 70px;
  border: 2px solid green;
  margin: 5px;
  font-size: 2em;
  text-align: center;
  line-height: 70px;
  justify-self: center;

/* Trick for a single word text: set the line-hight equal to the height of the element.

.drum-pad:hover {
  transform: scale(1.1);

#container {
  display: grid;
  grid-template-rows: 90px 90px 90px;
  grid-template-columns: 90px 90px 90px;
              const URL = "https://s3.amazonaws.com/freecodecamp/drums/";
  Q : "Heater-1",
  W : "Kick_n_Hat",
  E : "Chord_1",
  A : "Heater-6",
  S : "punchy_kick_1", 
  D : "Brk_Snr",
  Z : "Dry_Ohh",
  X : "Heater-3",
  C : "Dsc_Oh"

// This is to pass the last test.
const KEYCODES = {
  81 : 'Q',
  87 : 'W',
  69 : 'E',
  65 : 'A',
  83 : 'S',
  68 : 'D',
  90 : 'Z',
  88 : 'X',
  67 : 'C'

class App extends React.Component {
    this.state = { 
      currentSoundId: ''
    this.handleClickPlay = this.handleClickPlay.bind(this);
    this.handleKeyPress = this.handleKeyPress.bind(this);
    this.playSound = this.playSound.bind(this);
 componentDidMount() {
   document.addEventListener("keydown", this.handleKeyPress);
  componentWillUnmount() {
document.removeEventListener("keydown", this.handleKeyPress);

/* Play audio with javascript

The Joy of HTML5 Audio: Tips & Tricks for Easy Sound Embedding
  /* To do:
  It would be nice if when the user presses a key from the drum pad, the "button" reacts the same way as when the user hovers them with the mouse.
    // const key = event.key.toUpperCase();
    const key = KEYCODES[event.keyCode]; // this is to pass the last test.
    Here: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode 
    says that *keyCode* is deprecated and to avoid using it. 
    And here: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent
    it is recommended to use *key* instead.
    const isValidKey = Object.keys(SOUNDFILE_NAMES_AND_KEYS).includes(key);
    this.setState( { currentSoundId: (isValidKey)? key : '' } );
    this.setState( { currentSoundId: event.target.children[0].id } );
  render() {
    let message = 'No sound';
    if (this.state.currentSoundId) {
      message = `Sound: ${SOUNDFILE_NAMES_AND_KEYS[this.state.currentSoundId]}`;
    return (
      <div id="drum-machine">
        <Display currentSoundText={message}/>
        <div id="container">
            Object.keys(SOUNDFILE_NAMES_AND_KEYS).map((key) => {
              return (
                  soundFile={URL + SOUNDFILE_NAMES_AND_KEYS[key] + ".mp3"}

function Display(props){
    return (
    <div id="display">

function DrumPad(props) {
  return (
    <div className="drum-pad" id={props.soundFile} onClick={props.clickplayer}>
      <audio className="clip" id={props.name} src={props.soundFile} type="audio/mp3" ></audio>

ReactDOM.render(<App />, document.getElementById("app"));
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................