Trying to set a timer for my little game, but facing some difficulties.
The timer causes the balance to randomly increase from 0 to 13000 + some extra amount.
<script>
var coins = 0; var speed = 1;
</script>
<center>
<h4>
Coins Per Second:
<script type="text/javascript">
document.write(speed)
</script>
</h4>
</center>
<center>
<p id="coinspersecond">Coins: 0</p>
</center>
<button onclick="minecoins()"><img src="kop.png" height=28 width=32>Mine Coins</button>
<button onclick="stop()"><img src="kop.png" height=28 width=32>Stop Mining Coins</button>
<script>
function minecoins() {
coins = coins + speed
update()
}
function update() {
document.getElementById('coinspersecond').innerHTML = "Coins: " + coins;
setTimeout(update, 3000)
minecoins()
}
function stop() {
}
</script>