Answer the question
In order to leave comments, you need to log in
Random audio playback?
How can I implement random sound playback?
At the moment I have it set up like this:
if (sound == 'on') {
$('#bet2-sound')[0].play();
}
<audio id="bet2-sound" src="/sounds/Stavka-2.mp3" preload="auto"></audio>
Answer the question
In order to leave comments, you need to log in
Initially, a sound is randomly selected,
then in the event handler for which Sound2 is played, there is a check to see
if Sound2 is turned on, i.e.
{
$('#bet2-sound')[0].play();
}
We generate a random number in the desired range
function getRandomIntInRange(min, max) {
return Math.floor(Math.random() * (max + 1 - min) + min);
}
function playRandom() {
var rnd = getRandomIntInRange(1, 3)
document.getElementById('sound-' + rnd).play();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question