m0_70924714 2022-05-20 18:49 采纳率: 50%
浏览 85
已结题

Web前端开发JavaScript html

(1)计算每一个学生的总成绩,以表格形式输出
(2)按总成绩排名,以表格输出

img

img

  • 写回答

3条回答 默认 最新

  • Xiao_冬 2022-05-20 21:08
    关注

    img

    <!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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 5月21日
  • 已采纳回答 5月21日
  • 赞助了问题酬金5元 5月20日
  • 创建了问题 5月20日

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败