Skip to content
Advertisement

How to load all audio files on my page with js

i am trying to generate file paths to all audio files with js, but my script isn’t work as i expected. Here is my file structure:

JavaScript

https://github.com/TonnyHawk/solfege/tree/main/%23src/audio/36

As you can see there are only 12 filenames that repeated and only folder names change. i collected all posible file and folder names in this object

JavaScript

and supposed to generate paths like this audio / 36 / 3 / maj / octaves / 1 / a.mp3

JavaScript

but all that i recieving is just filenames for only one folder

JavaScript

seems like all for loops acting just one time and only notes() function goes through all pth.notes array. Can someone explain me this behaviour? I am open to hear your solutions

Advertisement

Answer

You need to assume or let the i variable in each function separately because it’s overridden by the previous value. Please check the below code or check js fiddle

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement