0

I am working on making a multiple choice quiz. The problem is sometimes the audio works, sometimes it does not. Here's the one I am trying:

var correct = new Audio("https://www.dropbox.com/s/ehdu5ilfh5f96h8/Sololearn%20Correct.mp3?dl=1&raw=1");
var wrong = new Audio("https://www.dropbox.com/s/zxbq3favobpexi3/Sololearn%20Wrong.mp3?dl=1&raw=1");  

or I just simply use which does not completely work at all....

var correct = new Audio("correctANSWER.mp3");
var wrong = new Audio("wrongANSWER.mp3");  

Hope someone can help me fix the problem. Thanks in advance!

mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • For your second version to work, you need to have the two files in the same folder as your HTML – mplungjan Jul 13 '20 at 08:42
  • None of these code blocks should generate any sound. You must call the `play()` method of one of these elements. Without seeing it, we can't help you. – Kaiido Jul 13 '20 at 08:55

2 Answers2

0

Declaring variables is only the first step. Using relative paths will only work if the files are stored on the same server.

  1. You need to write the code to decide if user input was correct or not.

  2. You also need to declare a player instance to play the correct clip when triggered by your evaluation of input.

Looks like your question is solved here : javascript - mp3 player in HTML website

svin83
  • 239
  • 1
  • 4
  • 13
0

you can do it via html and js, see this working example:

https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_audio_play

or you can do it with js only see this example:

Playing audio with JavaScript?

David Peer
  • 150
  • 1
  • 1
  • 12