эй, поэтому у меня есть массив с 8 звуками в нем, и сейчас у меня это есть, поэтому, когда я нажимаю на изображение, случайный звук из массива играет, его перемещают в новый массив , и когда исходный массив звуков пуст, новый массив передаст песни обратно в исходный массив.Переместить случайный элемент из одного массива в другой
-the problem is that when it removes the sound its not the sound that was just played.
-also id like to make clicking on the image multiple times not do anything other than playing the one sound until it finishes(then its moved to the empty array),then you can click the image for a new random sound
var sounds = [
"https://evolution.voxeo.com/library/audio/prompts/numbers/1.wav",
"https://evolution.voxeo.com/library/audio/prompts/numbers/2.wav",
"https://evolution.voxeo.com/library/audio/prompts/numbers/3.wav",
"https://evolution.voxeo.com/library/audio/prompts/numbers/4.wav",
"https://evolution.voxeo.com/library/audio/prompts/numbers/5.wav",
"https://evolution.voxeo.com/library/audio/prompts/numbers/6.wav",
"https://evolution.voxeo.com/library/audio/prompts/numbers/7.wav",
"https://evolution.voxeo.com/library/audio/prompts/numbers/8.wav"
];
var oldSounds = [];
function playSound()
{
var randomSound = sounds[Math.floor(Math.random() * sounds.length)];
document.getElementById("player").innerHTML=
"<embed src=\""+randomSound+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
//splice randomSound from sounds array into var removed
//than push that sound into oldSounds array
var removed = sounds.splice(randomSound, 1);
oldSounds.push(removed);
console.log("==song removed from sound array = " + removed);
console.log(" .sounds length = " + sounds.length);
console.log(" .oldSounds length = " + oldSounds.length);
//if all sounds played from sound array AND all sounds are now in oldSounds array
//than move the sounds from oldSounds to sounds
if (sounds.length === 0 && oldSounds.length === 8)
{
console.log("----------------");
sounds = oldSounds;
console.log("sounds length = " + sounds.length);
oldSounds = [];
console.log("oldSounds length = " + oldSounds.length);
console.log("----------------");
}
}
это то, что я до сих пор: http://jsbin.com/sekajumeva/1/edit?html,js,console,output
любая помощь будет оценена. Благодарю.
какой-то код будет лучше? не просто jsbin? – Mritunjay
Пожалуйста, подумайте о лучшем названии. – alex