Drum machine key triggers work but won't pass test

For some reason, my key triggers for the drum machine project are effectively triggering my audio elements and updating the display text with no detectable delay, but test #6 refuses to pass. As far as I can tell, I fulfilled the specifications to the letter, but it’s telling me that no audio plays when ‘Q’ is pressed and I get audio when I press Q. Any idea what could be causing this?

Probably not without seeing your code.

As said, we need to see your code.


Are you using the <audio> element or an Audio() constructor? The tests require you use the element.

Hi there, I am experiencing the same issue :confused:
This is my code: https://codepen.io/giuliapassoni/pen/poadqrQ
As per the suggestion above, I’m using the HTML audio element.

Thanks in advance for your help :slight_smile:

@kirakira95 It would be better if you opened your own thread. Anyway.

  1. You do not have access to this.handleKeyPress inside the Test component and there is no reason to call it inside it as you already have it listening on the document. Also, just as an aside don’t name the component Test.

  2. You should not assign props to state. Use the props directly (or create derived state from them).

  1. As far as I can tell, the bound function you are returning in the keydown handler will not be the same signature as the one you have for the event listener removal. I’d suggest binding the function in the constructor and passing the bound function to addEventListener/removeEventListener. I tested it by directly calling removeEventListener inside the handleKeyPress at the bottom to see if it gets removed or not.
1 Like

Thanks @lasjorg !

I’ll make sure to open a new thread next time :slight_smile: (still a novice at forums, sorry!).

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