zoukankan      html  css  js  c++  java
  • 用二维数组存一组学生的成绩,输出总成绩的是谁和分数,输出语文第一名是的谁和成绩

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>
    <script type="text/javascript">

    //一组学生的成绩,输出总成绩的是谁和分数,输出语文第一名是的谁和成绩
    var score = [
    {
    name: '小明',
    chinese: 128,
    math: 127,
    english:145
    },
    {
    name: '菜花',
    chinese: 139,
    math: 140,
    english:141
    },
    {
    name: '小芳',
    chinese: 148,
    math: 120,
    english:115
    },
    {
    name: '小李',
    chinese: 122,
    math: 148,
    english:115
    }
    ]



    //按照总成绩排序
    score.sort(function (a, b) {
    if(a.chinese + a.math + a.english > b.chinese + b.math + b.english)
    {
    return -1;
    } else
    {
    return 1;
    }
    })
    console.log('总成绩第一名的是 ' + score[0].name + ' 语文' + score[0].chinese + '数学' + score[0].math + '英语' + score[0].english)
    score.sort(function (a, b) {
    if(a.chinese > b.chinese)
    {
    return -1;
    } else
    {
    return 1;
    }
    })
    console.log('语文第一名姓名是 ' + score[0].name + ' 成绩' + score[0].chinese)
    </script>
    </head>
    <body>
    </body>
    </html>

    效果图 ↓

  • 相关阅读:
    句柄
    类,方法,抽象方法,接口
    Enum类型
    String 为什么是不可变的
    大数据怎么排序
    oracle创建表空间 导入数据库
    eclipse常见小问题
    eclipse创建项目
    存储过程
    在VMware通过挂载系统光盘搭建本地yum仓库
  • 原文地址:https://www.cnblogs.com/111lll/p/7435838.html
Copyright © 2011-2022 走看看