I have a value that increments by 0.015 every 90 milliseconds indefinitely. Now, I want to implement a feature where this incrementing stops randomly upon clicking a button. I have written code for it but unfortunately, it is not functioning as expected.
data:{
crashValue: 1,
},
methods:{
crashFunction: function() {
this.crashValue += 0.0150;
this.startTimer();
},
startTimer () {
let interval = 90
if (this.crashValue > 2.15) {
interval = 80
}
if (this.crashValue > 3.15) {
interval = 70
}
if (this.crashValue > 4) {
interval = 60
}
if (this.crashValue > 6.15) {
interval = 55
}
if (this.crashValue > 8) {
interval = 48
}
... additional conditions ...
this.tessst = setTimeout(this.crashFunction, interval);
},
randomStop(){
let randomNumber = Math.floor(Math.random() * 5000)
console.log(randomNumber)
clearTimeout(() => this.startTimer(), randomNumber)
},
}
<button class="stopCrash" :disabled="disableCashOut" @click="cashOut(); randomStop()">Cash out</button>