Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

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


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

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.


  <title>Front End Libraries Projects - Build a Drum Machine</title>
  <meta name="description" content="Build a Drum Machine">
  <meta name="keywords" content="HTML, CSS, JavaScript, React.js, freeCodeCamp, Front End Libraries Projects">
  <meta name="author" content="Chan Jian Hui Jonathan">
  <script src=""></script>


Hello Camper!

For now, the test suite only works in Chrome! Please read the README below in the JS Editor before beginning. Feel free to delete this message once you have read it. Good luck and Happy Coding! 

- The freeCodeCamp Team 

<div id="root"></div>


                $background: #092834;
$borders: #FE2712;
$root: #F0F7D4;
$pad: #347B98;
$active: #B2D732;

* {
  box-sizing: border-box;
  margin: 0px;
  font-family: sans-serif;

#root {
  display: grid;
  justify-items: center;
  align-content: center;
  height: 100vh;
  background-color: $root;

#drum-machine {
  background-color: $background;
  width: 80%;
  height: 400px;
  border: 5px solid $borders;
  display: grid;
  grid-template-columns: 2fr 1fr;
  grid-template-rows: 100%;
  align-content: center;
  justify-items: center;

.drum-pad, .drum-pad-active {
  border: none;
  padding: 20px;
  border-radius: 5px;
  height: 100%;
  font-weight: bold;
  font-size: 2em;
  display: grid;
  justify-content: center;
  align-items: center;
  user-select: none;

.drum-pad {
  background-color: $pad;

.drum-pad-active {
  background-color: $active;

#display {
  background-color: $pad;
  height: 50px;
  width: 90%;
  display: grid;
  justify-content: center;
  align-items: center;

#container-bank, #container-interface {
  width: 100%;
  display: grid;

#container-bank {
  grid-template-columns: 30% 30% 30%;
  grid-template-rows: 30% 30% 30%;
  justify-content: center;
  align-content: center;
  grid-gap: 10px 10px;

#container-interface {

  grid-template-columns: 100%;
  justify-items: center;
  align-content: center;


                // !! IMPORTANT README:

// You may add additional external JS and CSS as needed to complete the project, however the current external resource MUST remain in place for the tests to work. BABEL must also be left in place.

  - Select the project you would 
    like to complete from the dropdown 
  - Click the "RUN TESTS" button to
    run the tests against the blank 
  - Click the "TESTS" button to see 
    the individual test cases. 
    (should all be failing at first)
  - Start coding! As you fulfill each
    test case, you will see them go   
    from red to green.
  - As you start to build out your 
    project, when tests are failing, 
    you should get helpful errors 
    along the way!

// PLEASE NOTE: Adding global style rules using the * selector, or by adding rules to body {..} or html {..}, or to all elements within body or html, i.e. h1 {..}, has the potential to pollute the test suite's CSS. Try adding: * { color: red }, for a quick example!

// Once you have read the above messages, you can delete all comments.

const audios = {
  Q: {
    keypad: "Q",
    audio: "",
    displayText: "Heater 1"
  W: {
    keypad: "W",
    audio: "",
    displayText: "Heater 2"
  E: {
    keypad: "E",
    audio: "",
    displayText: "Heater 3"
  A: {
    keypad: "A",
    audio: "",
    displayText: "Heater 4"
  S: {
    keypad: "S",
    audio: "",
    displayText: "Clap"
  D: {
    keypad: "D",
    audio: "",
    displayText: "Open HH"
  Z: {
    keypad: "Z",
    audio: "",
    displayText: "Kick n' Hat"
  X: {
    keypad: "X",
    audio: "",
    displayText: "Kick"
  C: {
    keypad: "C",
    audio: "",
    displayText: "Closed HH"

const DrumPad = props => {
  const padId = props.keypad.displayText.replace(/\s/g, "-")
  return (
    <div onClick={props.onClick} id={padId} className="drum-pad">
      <audio src={} id={props.keypad.keypad} className="clip"/>

const PadBank = props => {
  return <div id="container-bank">{props.children}</div>;

const InterfaceBank = props => {
  return <div id="container-interface">{props.children}</div>

const Display = props => {
  return <h1 id="display">{props.display}</h1>;

class DrumMachine extends React.Component {
  constructor() {
    this.state = {
      display: "",
      volume: 1
  componentDidMount() {
    document.addEventListener("keydown", this.handleKeyPress);
  componentWillUnmount() {
    document.removeEventListener("keydown", this.handleKeyPress)
  handleKeyPress = event => {
    const keypress = event.key.toUpperCase();
    const elementPressed = document.getElementById(keypress).parentElement
  handleClick = event => {
    const element =
    const audio = element.querySelector("audio");
    const display = audios[].displayText
    setTimeout(() => element.classList.toggle("drum-pad-active"), 100)
  handleDisplay = display => {
      display: display
  handlePlay = audio => {
    audio.currentTime = 0;
    audio.volume = this.state.volume;
  render() {
    const drumPads = Object.values(audios).map(audio => (
      <DrumPad keypad={audio} key={audio.keypad} onClick={this.handleClick} />
    return (
      <div id="drum-machine">
          <Display display={this.state.display} />

ReactDOM.render(<DrumMachine />, document.getElementById("root"));