I would like to be able to take out the result of a timed event, but I am not sure how to find the index for it. The problem is that I am choosing an item from the array by time, but by index number, so I need to be able to get the result after the timer has run.
It will be along the lines of
mixedgroup1.splice(i, 1);
where i is the index number of the final result, but I cannot tell how to get it.
Any ideas?
Here is the JS code:
var basket = ['apple', 'banana', 'cherry', 'durian', 'eggplant', 'fig', 'grapes', 'huckleberry', 'kiwi', 'lemon', 'mango'];
function randOrd(){
return (Math.round(Math.random())-0.5); }
mixedBasket = basket.sort( randOrd ); //randomize the array
var i = 0; // the index of the current item to show
function showBasket(){
fruitDisplay = setInterval(function() {
document
.getElementById('fruit')
.innerHTML = mixedBasket[i++]; // get the item and increment
if (i == mixedBasket.length) i = 0; // reset to first element if you've reached the end
}, 70); //speed to display items
var endFruitDisplay = setTimeout(function( ) { clearInterval(fruitDisplay); }, 3600);
//stop display after x milliseconds
}
and this is the HTML:
<html>
<head></head>
<body>
<center>
<h1> <span id="fruit"></span><p></h1>
<script> var fruitSound = new Audio();
fruitSound.src = "boardfill.mp3";
function showFruitwithSound()
{
fruitSound.play(); // Play button sound now
showBasket()
}
</script>
<button onclick="showFruitwithSound()">Choose Fruit</button>
</center>
<script type="text/javascript" src="Fruitpicker3.js"></script>
</body>
</html>