No, using src is not the answer. How do I know? Because I have your drum machine working locally here on my computer
Look in App.js, where you are creating each DrumPad. What are the names of the attributes you are passing to the DrumpPad? Those are the prop names you need to use in DrumPad.js. There is no value for this.props.name in DrumPad.js because you aren’t passing an attribute with the name name when you create the DrumPad in App.js.
<audio
className='clip'
src={this.props.src}
id = {this.props.name}
type='audio/mp3'>
</audio>
Look at what you are setting the id attribute with. I’m pretty sure we just came to the realization that this.props.name doesn’t exist in DrumpPad.js. Remember, you can only use props names that you pass into DrumpPad when creating the DrumPads in App.js.
Are you able to click on your drum pads now and get a sound? From what you have pasted above it seems like you should be able to, but if not then you’ll have to update github with your current code so I can see everything.
I will tell you though that right now one of your drum pads will not work and will throw an error when clicked on. I’m not going to tell you which one but I will give you a hint: id’s cannot have spaces in them.
Ahh, so now you’ve got an HTML issue, not a JS issue. HTML element id’s must be unique. The <div> that wraps the <audio> can’t have the same id as the <audio>. The fix is in the JS (since you are creating the elements there), but it’s not really a JS issue, it’s just invalid HTML.
I think once you fix this you should start hearing sounds. Have fun.
I’ve passed all of my tests except for the final one. I need text to show up in my display to indicate which drum-pad is triggered. I have a display component (in Display.js) as well as a message variable set to ‘no sound’. However, I’m not sure how to go about setting the name attribute from Sounds to be triggered in the display. Is this something that can be linked to the DrumPad component? Currently, I have code to update the message variable that looks like this:
Remember how you originally had a playSound method in App.js, and you passed that method to DrumPad, and then DrumPad would call the App.playSound method when the user clicked a button? The advantage of doing it that way is that App would know which button is clicked, which would then allow it to get that information to Display. The way you have it working right now is that DrumPad knows the button is clicked, and it plays the sounds itself, and that’s it, it doesn’t communicate with App about which button was clicked. So there is no way for App to tell Display which button is clicked
I think you want the sound name to show in the display when you press a key on the keyboard, right?
The way you are adding the keydown handler is creating multiple unnecessary handlers. If you know how to look at the event listeners in the dev tools you’ll see that you have added 9 keydown event handlers that all do the same thing because a keydown handler is added for every DrumPad you are creating. I think you need to add that handler once in App instead.
Speaking of the keydown handler, try hitting the space bar. You’ll want to make sure that you have a valid DrumPad key before you call querySelector. Or you could use a try/catch to ignore the exception that occurs when it is not.