阅读以下代码,并对其进行完善,使其增加计算平均绩点的功能:<!doctype html> <html> <head> <meta charset="utf-8">…
- User
阅读以下代码,并对其进行完善,使其增加计算平均绩点的功能:
function calculateScoreGPA(score) { if (score >= 90) { return 4.0; } else if (score >= 85) { return 3.7; } else if (score >= 82) { return 3.3; } else if (score >= 78) { return 3.0; } else if (score >= 75) { return 2.7; } else if (score >= 72) { return 2.3; } else if (score >= 68) { return 2.0; } else if (score >= 66) { return 1.7; } else if (score >= 64) { return 1.3; } else if (score >= 60) { return 1.0; } else { return 0.0; } }
2022-2023学年第二学期
code<tr> <td>形势与政策</td> <td>0.5</td> <td> </td> <td> <input type="number" id="score_course13" /> <button onclick="calculateGPA('course13')">计算绩点</button> </td> <td><span id="gpa_course13"></span></td> </tr> <tr> <td>体育</td> <td>0.5</td> <td> </td> <td> <input type="number" id="score_course14" /> <button onclick="calculateGPA('course14')">计算绩点</button> </td> <td><span id="gpa_course14"></span></td> </tr> <tr> <td>大学英语</td> <td>1.5</td> <td> </td> <td> <input type="number" id="score_course15" /> <button onclick="calculateGPA('course15')">计算绩点</button> </td> <td><span id="gpa_course15"></span></td> </tr> <tr> <td>大学生心理健康</td> <td>2</td> <td> </td> <td> <input type="number" id="score_course16" /> <button onclick="calculateGPA('course16')">计算绩点</button> </td> <td><span id="gpa_course16"></span></td> </tr> <tr> <td>高等数学A2</td> <td>6</td> <td><img src="../Desktop/BP/image/.jpeg" width="500" height="500" alt=""/></td> <td> <input type="number" id="score_course17" /> <button onclick="calculateGPA('course17')">计算绩点</button> </td> <td><span id="gpa_course17"></span></td> </tr> <tr> <td>线性代数A</td> <td>3</td> <td><img src="../Desktop/BP/image/u=1665676147,639385142&fm=253&fmt=auto&app=138&f=JPEG.jpg" alt=""/></td> <td> <input type="number" id="score_course18" /> <button onclick="calculateGPA('course18')">计算绩点</button> </td> <td><span id="gpa_course18"></span></td> </tr> <tr> <td>离散数学</td> <td>4</td> <td><img src="../Desktop/BP/image/f9144da186a132ef51112ebfa8925434.jpg" width="800" height="800" alt=""/></td> <td> <input type="number" id="score_course19" /> <button onclick="calculateGPA('course19')">计算绩点</button> </td> <td><span id="gpa_course19"></span></td> </tr> <tr> <td>遥感原理与应用</td> <td>2.5</td> <td><img src="../Desktop/BP/image/38be83ff15039adc2513f777eda14b37.jpg" width="800" height="1132" alt=""/></td> <td> <input type="number" id="score_course20" /> <button onclick="calculateGPA('course20')">计算绩点</button> </td> <td><span id="gpa_course20"></span></td> </tr> <tr> <td>大学物理B</td> <td>3.5</td> <td> </td> <td> <input type="number" id="score_course21" /> <button onclick="calculateGPA('course21')">计算绩点</button> </td> <td><span id="gpa_course21"></span></td> </tr> - Assistant
完善代码的思路如下:
- 在每个课程的得分输入框中,添加一个按钮,点击按钮时调用calculateGPA函数,并传递当前课程的标识符作为参数。
- 在calculateGPA函数中,根据传入的课程标识符获取对应的得分输入框的值,然后调用calculateScoreGPA函数计算绩点,并将计算结果展示在对应的绩点显示框中。