我在最后用 JS 写了一个函数,一旦你得到 5 个科目的平均值,它就会给你一个字母等级,但它没有向我显示任何东西 我现在迷路了
我编写的第四个函数似乎没有产生任何字母等级。我相信其他一切都是对的
function getHandleValue(idName) { const value = parseInt(document.getElementById(idName).value); console.log(value); return value; } function getTotal() { //console.log("app js starts loading") let english = getHandleValue('english'); let math = getHandleValue('math'); let physics = getHandleValue('physics'); let computer = getHandleValue('computer'); let science = getHandleValue('science'); //console.log("app js ends loading") let total = english + math + physics + computer + science; document.getElementById('total').innerHTML = total; return total; } function getAverage() { // option 1 // const total = parseInt(document.getElementById('total').innerHTML); // const average = total / 5; // document.getElementById('average').innerHTML = average; // option 2 const average = getTotal() / 5; document.getElementById('average').innerHTML = average; } function letterGrade() { letterGrade; if (grade >= 90 && grade <= 100) letterGrade = 'A'; else if (grade >= 80 && grade <= 89) letterGrade = 'B'; else if (grade >= 70 && grade <= 79) letterGrade = 'C'; else if (grade >= 60 && grade <= 69) letterGrade = 'D'; else if (grade > 1 && grade <= 59) letterGrade = 'F'; let average = letterGrade; document.getElementById('Grade').innerHTML = Grade; }
P粉6474494442024-04-02 00:33:50
letterGrade
未正确声明,请执行以下操作:
let letterGrade = ' '
这声明了 letterGrade 变量
。