I have 4 audio files, and I need them to play in some order, but in a way so they play ONLY when previous has ended playing - one after another.
Here is my attempt
"use strict"
var sound0 = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound1.mp3");
var sound1 = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound2.mp3");
var sound2 = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound3.mp3");
var sound3 = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound4.mp3");
var a = [0, 1, 2, 3];
function play1() {
for (let i = 0; i < a.length; i++) {
if (a[i] === 0) {
sound0.play();
} else if (a[i] === 1) {
sound1.play();
} else if (a[i] === 2) {
sound2.play();
} else if (a[i] === 3) {
sound3.play();
}
}
};
<div>
<button id="playBtn" onclick="play1()">Play</button>
</div>