(1)计算每一个学生的总成绩,以表格形式输出
(2)按总成绩排名,以表格输出
3条回答 默认 最新
- Xiao_冬 2022-05-20 21:08关注
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> table { border: 1px solid #000; margin-bottom: 20px; } table td, table th { border: 1px solid #000; text-align: center; width: 100px; } </style> </head> <body> <script> const list = [ { stuNo: 1, course1: 77, course2: 66, course3: 88, total: "", }, { stuNo: 2, course1: 78, course2: 89, course3: 79, total: "", }, { stuNo: 3, course1: 92, course2: 84, course3: 78, total: "", }, { stuNo: 4, course1: 78, course2: 99, course3: 83, total: "", }, { stuNo: 5, course1: 85, course2: 97, course3: 69, total: "", }, ]; const totalList = list.map((item) => { const { course1, course2, course3 } = item; // 暂时以course1,course2,course3为准 item.total = course1 + course2 + course3; return item; }); const rankList = [...totalList]; rankList.sort((a, b) => b.total - a.total); const str1 = totalList.reduce((pre, cur) => { const temp = `<tr> <td>${cur.stuNo}</td> <td>${cur.course1}</td> <td>${cur.course2}</td> <td>${cur.course3}</td> <td>${cur.total}</td> </tr>`; return pre + temp; }, ""); const str2 = rankList.reduce((pre, cur) => { const temp = `<tr> <td>${cur.stuNo}</td> <td>${cur.course1}</td> <td>${cur.course2}</td> <td>${cur.course3}</td> <td>${cur.total}</td> </tr>`; return pre + temp; }, ""); const tableTemplate = `<table><tr><th>stuNo</th><th>course1</th> <th>course2</th> <th>course3</th> <th>total</th></tr>`; document.body.innerHTML = `${tableTemplate}${str1}</table>` + `${tableTemplate}${str2}</table>`; </script> </body> </html>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 preLaunchTask"C/C++: aarch64- apple-darwin22-g++-14 生成活动 文件”已终止,退出代码为-1。
- ¥18 关于#贝叶斯概率#的问题:这篇文章中利用em算法求出了对数似然值作为概率表参数,然后进行概率表计算,这个概率表是怎样计算的呀
- ¥20 C#上传XML格式数据
- ¥15 elementui上传结合oss接口断点续传,现在只差停止上传和继续上传,各大精英看下
- ¥100 单片机hardfaulr
- ¥20 手机截图相片分辨率降低一半
- ¥50 求一段sql语句,遇到小难题了,可以50米解决
- ¥15 速求,对多种商品的购买力优化问题(用遗传算法、枚举法、粒子群算法、模拟退火算法等方法求解)
- ¥100 速求!商品购买力最优化问题(用遗传算法求解,给出python代码)
- ¥15 虚拟机检测,可以是封装好的DLL,可付费