间隔不加起来

时间:2017-07-30 21:52:49

标签: javascript

好吧,所以我把它放在一起,

var ms = 0;
var currentCrashNumber = 100;
var nextIncrease = 1.25;
var userIncrease = 1.25;
var multiplierInterval = setInterval(function(){
  currentCrashNumber=currentCrashNumber + 10/(3.5/(nextIncrease - nextIncrease/1.25))/1000;
  console.log(currentCrashNumber);
  ms=ms+10;
  if(currentCrashNumber >= nextIncrease){
    console.log(ms);
    nextIncrease = nextIncrease*(userIncrease);
  }                 
  if(currentCrashNumber >= 305){
    console.log('Script done in ' + ms + 'ms');
    clearInterval(multiplierInterval);
  }
}, 10);

这段代码将在17500ms或17.5s内完成。当我启动代码时,它最终将导致大约17500毫秒。

但是,当我使用我的秒表计时时,我最终会超过19000毫秒或19.0秒,为什么会这样,我该如何解决?

小提琴:https://jsfiddle.net/2wbbprfj/

我的网站上有一个进度条,这是一些后端编码,但是当持续17.5秒的进度条到达结尾时,脚本还没有完成,这很奇怪,因为它们都被编程为结束在17500ms

0 个答案:

没有答案