Drum Machine Testing Failed

I’m working on Drum Machine project. My project seems to work fine, everything works well, however, the testing shows it failed. I couldn’t able to pass these 2 test cases:


When I click on a .drum-pad element, the audio clip contained in its child <audio> element should be triggered.


When I press the trigger key associated with each .drum-pad, the audio clip contained in its child <audio> element should be triggered (e.g. pressing the Q key should trigger the drum pad which contains the string "Q", pressing the W key should trigger the drum pad which contains the string "W", etc.).

Here is my code. Please point me out what am I doing wrong in the code for my project.

import React, { useState } from 'react';
import './App.css';

function App() {

  const DRUM_NOTES = [
         note:'Heater 1', source:'https://s3.amazonaws.com/freecodecamp/drums/Heater-1.mp3'},
         key:'W', note:'Heater 2', source:'https://s3.amazonaws.com/freecodecamp/drums/Heater-2.mp3'},
         key:'E', note:'Heater 3', source:'https://s3.amazonaws.com/freecodecamp/drums/Heater-3.mp3'},
         key:'A', note:'Heater 4', source:'https://s3.amazonaws.com/freecodecamp/drums/Heater-4.mp3'},
         key:'S', note:'Clap', source:'https://s3.amazonaws.com/freecodecamp/drums/Heater-6.mp3'},
         key:'D', note:'Open-HH', source:'https://s3.amazonaws.com/freecodecamp/drums/Dsc_Oh.mp3'},
         key:'Z', note:'Kick-n\'-Hat', source:'https://s3.amazonaws.com/freecodecamp/drums/Kick_n_Hat.mp3'},
         key:'X', note:'Kick', source:'https://s3.amazonaws.com/freecodecamp/drums/RP4_KICK_1.mp3'},
         key:'C', note:'Close-HH', source:'https://s3.amazonaws.com/freecodecamp/drums/Cev_H2.mp3'},

  const [drumNote, setDrumNote] = React.useState('');

  const playMusic = (event) => {
  try {
    const drumKeyCode = DRUM_NOTES.find((drumNote)=> {
      return(drumNote.key === event.key || drumNote.key === event.target.innerText)


    if (drumKeyCode) {
      const audioSrc = document.getElementById(drumKeyCode.key);
      const drumPad = document.getElementById(drumKeyCode.id);


      audioSrc.currentTime = 0;
  } catch (error) {

  const drumTabs = DRUM_NOTES.map((drumNote)=> {
    return (
      <div className='drum-pad' id={drumNote.id} key={drumNote.key}
        onClick={(e)=> {playMusic(e)}}>
        <audio src={drumNote.source} className='clip' id={drumNote.key}
          key={drumNote.note} type='audio/mp4'/>

   <div className='container-fluid d-flex justify-content-center align-items-center flex-column bg-dark'
      <div id="drum-machine" 
      className='drum-container p-2 bg-secondary row rounded-4
      d-sm-flex justify-content-around align-items-center flex-column' style={{
      <div className='col-sm-6 col-12 m-1 p-2 d-flex flex-wrap justify-content-around align-items-center'>
        <div className='drumbox d-flex justify-content-around align-items-center flex-wrap rounded-4'>
      <div className='col-sm-6 col-12'>
        <h5 className='text-center' id='display'>{drumNote}</h5>

export default App;

I think you are likely to get more help if you can provide us with a link to the project so that we can test it without having to copy/paste and set up everything ourselves. Perhaps put it in codepen or something similar.

We are lazy by nature. Don’t make us do any work to help you :slight_smile:

Here is my live link - Drum-Machine - Replit

Look closely at the red error message:

The <audio> element with id="A" does not play when the A .drum-pad is clicked

The sound for the A drum pad is not working. I think you need to get a new sound for it. You can see an error in the console each time you click it.

Looks like nothing happens when I press keys on keyboard.

I am not sure if onClick event does the good job in terms of providing functionality for handling pressing the keys
You may wanna do research about keyboard events.

There are some issues in the console:
Warning: You are importing createRoot from "react-dom" which is not supported. You should instead import it from "react-dom/client".

Also, looks like one of the source audio links is broken somehow.
You may wanna test ‘A’ button functionality.

on first load of the page console gives:
GET https://s3.amazonaws.com/freecodecamp/drums/Heater-4.mp3 403 (Forbidden)

on click of ‘A’ button:
App.jsx:48 Uncaught (in promise) DOMException: The element has no supported sources.

ohh, right. I forgot to add this line
document.addEventListener('keydown', playMusic);

Now, it’s all passed. thank you

thank you, I fixed new link for A drum and it works now.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.