较低等级的评分计算器方程式

Grading Calculator Equation for lesser grades

我正在尝试创建一个计算器,当你输入你的分数时,class 中的总分数你会收到很多关于它的信息,我目前正在处理字母等级,百分比,以及升到下一个等级所需的分数。 前任。 95/100

95%

需要的分数 = 5

我想用需要的点数做同样的事情,但相反。因此,对于相同的示例,它将是

失分 = 5

如果有帮助的话,我目前有我当前需要的点数的脚本,但我真的无法弄清楚这个方程式,幸运的是对于学校项目来说不需要,只是对于一个单独的项目,所以我可以学习如何编码。

这是需要积分的代码

        var pointsNeeded = totalGrade.value - grade.value; 
            if (gradePercentage > 100) {
                pointsNeeded = pointsNeeded * -1; 
                document.getElementById("pointsNeeded").innerHTML = "You can lose " + pointsNeeded + " point(s) and still have 100%"; 
            }
            else {
                document.getElementById("pointsNeeded").innerHTML = pointsNeeded; 
            }
    }
    else if (gradePercentage < 89, gradePercentage > 79) {
        var pointsNeeded = Math.round(10 * ((totalGrade.value * 0.9) -               
        grade.value)) / 10; 
        document.getElementById("pointsNeeded").innerHTML = pointsNeeded; 
    }
    else if (gradePercentage < 79, gradePercentage > 69) {
        var pointsNeeded = Math.round(10 * ((totalGrade.value * 0.8) -               
        grade.value)) / 10; 
        document.getElementById("pointsNeeded").innerHTML = pointsNeeded; 
    }
    else if (gradePercentage < 69, gradePercentage > 59) {
        var pointsNeeded = Math.round(10 * ((totalGrade.value * 0.7) -               
        grade.value)) / 10; 
        document.getElementById("pointsNeeded").innerHTML = pointsNeeded; 
    }
    else if (gradePercentage < 59) {
        var pointsNeeded = Math.round(10 * ((totalGrade.value * 0.6) -              
        grade.value)) / 10; 
        document.getElementById("pointsNeeded").innerHTML = pointsNeeded; 
    }

gradePercentage 是实际百分比,totalGrade 是完整成绩,grade 是你的成绩。

这些也是等级值,

        var gradeLetter = "A"
            document.getElementById("result").innerHTML = gradeLetter +                    " " + result + "%";          
    }
    if (gradePercentage > 79.9, gradePercentage < 90) {
        var gradeLetter = "B"
            document.getElementById("result").innerHTML = gradeLetter +                    " " + result + "%";
    }
    if (gradePercentage > 69.9, gradePercentage < 80) {
        var gradeLetter = "C"
            document.getElementById("result").innerHTML = gradeLetter +                    " " + result + "%";
    }
    if (gradePercentage > 59.9, gradePercentage < 70) {
        var gradeLetter = "D"
            document.getElementById("result").innerHTML = gradeLetter +                    " " + result + "%";          
    }
    if (gradePercentage < 59.9) {
        var gradeLetter = "F"
            document.getElementById("result").innerHTML = gradeLetter +                    " " + result + "%";  
    }   

这段代码很漂亮self-explanatory:

let startingPoints = 952.3 // How many points you got on the test
let maxPoints = 1049 // Max possible points you could have gotten

// Your grade (0-100%):
let gradePercentage = 100 * startingPoints / maxPoints; // E.g. 90.7816968541468

// How much less you'd need (as a percentage) to get the next lowest grade:

let extraPercentage = ( gradePercentage % 10 ) + 0.01; // E.g. 0.7916968541468015

// Your new grade (as a percentage) if you bumped it down:
let newGrade = gradePercentage - extraPercentage; // E.g. 89.99

// How many points you'd have to reduce your score by to bump it down to the next lowest 
let extraPoints = ( extraPercentage / 100 * maxPoints ) // E.g. 8.304899999999947

// What your score would be if you bumped it down to the next level:
let newExtraPoints = startingPoints - extraPoints; // E.g. 943.9951

console.log( `Your grade is ${gradePercentage}% (${startingPoints} points out of a possible ${maxPoints}). If you subtract ${extraPercentage}% (or ${extraPoints} points), your grade will be ${newGrade}% (${newExtraPoints} points)` );

唯一的技巧是我们要添加 0.01,技术上可以是 0.001,或 0.0001,或者......好吧,我们必须添加 something 以低于限制,并且没有设置“正确”的数量,我选择 0.01,因为它效果很好。

示例输出:

Your grade is 90.7816968541468% (952.3 points out of a possible 1049).
If you subtract 0.7916968541468015% (or 8.304899999999947 points),
your grade will be 89.99% (943.9951 points)