我在最後用 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 變數
。