在JavaScript中返回NaN的简单计算

时间:2017-02-16 09:39:04

标签: javascript decimal-point

我试图在JavaScript中执行基本计算,从整数中取一个小数点,无论我尝试什么,我都会在控制台中收到Not a Number(NaN)错误。我的起始编号为1000,然后对于SetInterval函数的每个循环,我想减去0.1。

this.StartTimer = function () {
        var width = 100;
        this.QuestionScore = 1000;
        var thisQuiz = this;
        var elem = document.getElementById("barStatus");   
        // Set Interval
        var timer = setInterval(frame, 30);
        function frame() {
            if (width <= 0) {
                // Move to next Question when timer is up
                clearInterval(timer);
                elem.style.width = 100 + '%';
                if (this.QuestionsGone == 9) {
                    thisQuiz.GetSummary(this.Type);
                } else {
                    thisQuiz.AnswerQuestion(-1, 0);
                }
            } else {
                // Increase Status Bar Each Interval
                width = width - 0.1; 
                this.QuestionScore = this.QuestionScore - 0.1;
                console.log(this.QuestionScore);
                this.QuestionScore = Math.ceil(this.QuestionScore * 10) / 10;
                console.log(this.QuestionScore);
                elem.style.width = width + '%'; 
            }
        }
    }

0 个答案:

没有答案