javascript - Accessing audio files from an array of Objects -


I'm trying to add an audio aspect in an HTML / Javascript quiz (see JSFiddle :) I have an empty audio tag:

  & lt; Audio id = "myAudio" src = "" control & gt; & Lt; / Audio & gt;   

Which I want to play with my array 'question' property:

  var allQuestions = [{Question: "http: //www.w3schools. Com / html / horse.mp3 ", option: [" 3 "," 5th "," 4th "], correct answer: 2},   

This is the format of my audio player Does not work in. My function is clearly incorrect in some way to send data to the audio player from the object that does not load anything. Can someone help me in some amount of light but I am doing something wrong?

This is not the full answer but see if it takes you in the right direction.

Actually you can change the audio src via javascript. So I changed it with an object property when the user clicks on the next button. The first source default for the initial source of the audio tag. If you want you can modify the code but I think it's fine as it may be. var allQuestions = [{Question: "Identify music interval", option: ["3", "5," 4 "), correct answer: 2, AudioSRC:" Original. Ogg file defaults "}, {Question:" Which of the following describes the best of this string? ", Option: [" Major "," Minor "," Dim "], Correct Answer: 0, AudioSRC: function nextQuestion () {updateScore (); questionCount ++; showScore (); showQuestion (); var audio = document.getElementById ('myAudio') audio.src = (All questions [question] number. Audio src) ;}

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -