以下代码生成一个介于最小值和最大值之间的随机数,并逐渐增加到设置的数(999)。我需要脚本来递减计数。为此,我将+1替换为-1,它可以正常工作。但是,现在我还需要设置倒数到达编号。例如,现在我在999处输入到达数字15,该脚本从81开始计数到15。请问我该怎么做?
<div id="divCounter"></div>
var min = 80;
var max = 85;
var random = Math.floor(Math.random() * (+max - +min)) + +min;
if (localStorage.getItem("counter")) {
if (localStorage.getItem("counter") >= 1000) { // Time duration localStorage
var value = random;
} else {
var value = localStorage.getItem("counter");
}
} else {
var value = random;
}
document.getElementById('divCounter').innerHTML = value;
var counter = function () {
if (value >= 999) { // maximum count
localStorage.setItem("counter", random);
value = random;
} else {
value = parseInt(value) + 1; // -1
localStorage.setItem("counter", value);
}
document.getElementById('divCounter').innerHTML = value;
};
var interval = setInterval(function () {
counter();
}, 100); // time speed