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>

    效果图 ↓

  • 相关阅读:
    KMP算法
    Python 正则表达式
    Python 装饰器
    C/C++ 之输入输出
    PAT(Basic Level)--个位数统计
    Java 接口与抽象类
    Java集合-01概述
    数据结构--红黑树
    数据结构--(AVL)平衡二叉树
    数据结构--二叉搜索树
  • 原文地址:https://www.cnblogs.com/111lll/p/7435838.html
Copyright © 2011-2022 走看看