来自 class 函数的 Javascript 中的 NaN 输出

NaN output in Javascript from a class function

我需要解决以下问题:

使用下一个字段创建 class 实习生: 名称(字符串) 姓氏(字符串) 懒惰(数字从 20 到 50) 好奇心(从 0 到 100 的数字) 技能(从 0 到 100 的数字) 不负责任(从 0.0 到 1.0 的浮点数) 为此class创建计算实习生“标记”的方法,这是通过公式计算的(在代码中) 它看起来很简单,但是当我 运行 它时,输出是 NaN。有人可以帮忙吗?

class Intern {
    constructor(name, surname, laziness, curiosity, skill, irresponsibility) {
        this.name = name
        this.surname = surname
        if (laziness <= 50 && laziness >= 20) {
            this.laziness = laziness
        } else {
            this.laziness = 0
        }

        if (curiosity <= 100 && curiosity >= 0) {
            this.curiosity = curiosity
        }
        if (skill <= 100 && skill >= 0) {
            this.skill = skill
        }
        if (irresponsibility <= 0 && irresponsibility >= 1) {
            this.irresponsibility = irresponsibility
        }
    }

    getMark() {
        let mark = (((this.skill + this.curiosity) * (1.5 - this.irresponsability)) / (this.laziness * 0.25));
        return mark
    }
}

您在 getMark() 方法中拼错了 irresponsibility 变量,并且构造函数中的 if 语句永远不会为真:

if (irresponsibility <=0 && irresponsibility >=1)

我想你的意思是:

if (irresponsibility >=0 && irresponsibility >=1)