Skip to content
Advertisement

Playing audio along with a random array of words

Hello everyone i want to know how can i play each audio files with certain words in this code. I want to make my quiz and my friend send me this. It kinda work but now i want that when clicking a word, when the word appear the pronounciation of that word also need to be played, i added the audioFiles array in here but i don’t know how can i attach it with the word array in Javascript. Someone help me please, Thank you a lot.

Below here is the HTML code

JavaScript

And here is the Javascript code

JavaScript

Advertisement

Answer

In your click() function, you can reference the letter (or word) and find the mp3 with the same name:

JavaScript

See working snippet below. You won’t hear a sound bc those mp3’s aren’t here, but you’ll see the console.log when it should play

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