Having a problem with Audio objects being used in my Simon code

Having a problem with Audio objects being used in my Simon code
0.0 0

#1

Hi, still working on Simon. Here’s the link to my codepen: https://codepen.io/glennqhurd/pen/EQqxKe

Today’s problem is that I’m getting an error when I use the click events to play a sound. The error is:
Uncaught TypeError: Cannot read property ‘play’ of undefined
at VM95 pen.js:164

It’s referring to the code errorSound.sound.play() at line 164. However, I defined the variable on line 12. I also use the exact code with a different variable in a different function called buttonFlash which is line 70 and 73. The sounds play when buttonFlash is called but not with a click event. Also, I was trying this with the variable buttonSound1 at first which is also used by buttonFlash and got the same error as above. I’m not sure if it’s a scoping issue or something else that I’m missing entirely. Any help is appreciated.


#2

Interesting sound effect when you press on/off! :rofl:
A bit like R2-D2. I will inspect your code and try to figure it out.

I have had a try to improve it but because there are no comments it is hard to follow the logic.
At least the R2-D2 beeping has stopped!


#3

This was a link to a html file not a valid audio file.


#4

Right, also errorSound.sound.play() is incorrect. The .sound part was used in my code earlier since .sound was a property of an object so that was why it wasn’t working w/ buttonSound1. I fixed it in the code.