用html在Visual Studio Code软件环境下写一个班级成绩单,要求有班级平均分、分段分数统计等信息并且利用script计算平均分,分数段(要求使用跨行跨列)
时间: 2023-06-01 16:02:01 浏览: 153
编写程序,输入并保存5名学生的信息,计算出平均分,再按照成绩从高到低的顺序输出他们的信息。学生信息包括:学号、姓名、成绩。
<!DOCTYPE html>
<html>
<head>
<title>班级成绩单</title>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
text-align: center;
padding: 10px;
}
th {
background-color: #e6e6e6;
}
</style>
</head>
<body>
<h1>班级成绩单</h1>
<table>
<thead>
<tr>
<th rowspan="2">姓名</th>
<th colspan="3">考试成绩</th>
<th rowspan="2">总分</th>
</tr>
<tr>
<th>语文</th>
<th>数学</th>
<th>英语</th>
</tr>
</thead>
<tbody>
<tr>
<td>张三</td>
<td>90</td>
<td>80</td>
<td>85</td>
<td>255</td>
</tr>
<tr>
<td>李四</td>
<td>80</td>
<td>75</td>
<td>90</td>
<td>245</td>
</tr>
<tr>
<td>王五</td>
<td>85</td>
<td>90</td>
<td>75</td>
<td>250</td>
</tr>
<tr>
<td>赵六</td>
<td>70</td>
<td>85</td>
<td>80</td>
<td>235</td>
</tr>
<tr>
<td>平均分</td>
<td id="chinese"></td>
<td id="math"></td>
<td id="english"></td>
<td id="total"></td>
</tr>
<tr>
<td>分段统计</td>
<td>90-100分</td>
<td>80-89分</td>
<td>70-79分</td>
<td>60-69分</td>
</tr>
<tr>
<td>人数</td>
<td id="a"></td>
<td id="b"></td>
<td id="c"></td>
<td id="d"></td>
</tr>
</tbody>
</table>
<script>
var chinese = [90, 80, 85, 70];
var math = [80, 75, 90, 85];
var english = [85, 90, 75, 80];
var total = [];
var a = 0, b = 0, c = 0, d = 0;
for (var i = 0; i < chinese.length; i++) {
total[i] = chinese[i] + math[i] + english[i];
if (total[i] >= 90) {
a++;
} else if (total[i] >= 80) {
b++;
} else if (total[i] >= 70) {
c++;
} else {
d++;
}
}
document.getElementById("chinese").innerHTML = (chinese.reduce((a, b) => a + b) / chinese.length).toFixed(2);
document.getElementById("math").innerHTML = (math.reduce((a, b) => a + b) / math.length).toFixed(2);
document.getElementById("english").innerHTML = (english.reduce((a, b) => a + b) / english.length).toFixed(2);
document.getElementById("total").innerHTML = (total.reduce((a, b) => a + b)).toFixed(2);
document.getElementById("a").innerHTML = a;
document.getElementById("b").innerHTML = b;
document.getElementById("c").innerHTML = c;
document.getElementById("d").innerHTML = d;
</script>
</body>
</html>
阅读全文