以下是某班级一次考试的成绩表。请计算每个学生总成绩,并按总成绩排名。统计各单科成绩第一名,输出其成绩与学号。

var data = [
    { StudentNumber: 2022003, Chinese: 86, Math: 64, English: 80, TotalScore: "", Comment: "" },
    { StudentNumber: 2022004, Chinese: 78, Math: 99, English: 91, TotalScore: "", Comment: "" },
    { StudentNumber: 2022005, Chinese: 107.5, Math: 97, English: 70, TotalScore: "", Comment: "" },
    { StudentNumber: 2022006, Chinese: 112, Math: 61, English: 92, TotalScore: "", Comment: "" },
    { StudentNumber: 2022007, Chinese: 101, Math: 79, English: 104, TotalScore: "", Comment: "" },
    { StudentNumber: 2022008, Chinese: 71, Math: 72, English: 105, TotalScore: "", Comment: "" },
    { StudentNumber: 2022009, Chinese: 56, Math: 68, English: 61, TotalScore: "", Comment: "" },
    { StudentNumber: 2022010, Chinese: 98, Math: 83, English: 77, TotalScore: "", Comment: "" }
];

  • 并根据总成绩计算每个学生成绩备注保存在 Comment 中,110分以上为A,100分以上为B,90分以上为C,72分以上为D,72分以下为E

     var data = [
        { StudentNumber: 2022003, Chinese: 86, Math: 64, English: 80, TotalScore: "", Comment: "" },
        { StudentNumber: 2022004, Chinese: 78, Math: 99, English: 91, TotalScore: "", Comment: "" },
        { StudentNumber: 2022005, Chinese: 107.5, Math: 97, English: 70, TotalScore: "", Comment: "" },
        { StudentNumber: 2022006, Chinese: 112, Math: 61, English: 92, TotalScore: "", Comment: "" },
        { StudentNumber: 2022007, Chinese: 101, Math: 79, English: 104, TotalScore: "", Comment: "" },
        { StudentNumber: 2022008, Chinese: 71, Math: 72, English: 105, TotalScore: "", Comment: "" },
        { StudentNumber: 2022009, Chinese: 56, Math: 68, English: 61, TotalScore: "", Comment: "" },
        { StudentNumber: 2022010, Chinese: 98, Math: 83, English: 77, TotalScore: "", Comment: "" }
    ];
       function ScoreHandling(data){
       this.data=data;
    }
       ScoreHandling.prototype.scoreSort=function(data,subject,subjectText){
           data.sort(function(a,b){
            return b[subject]-a[subject];  
       })
       document.write(subjectText + '第一名是:' + data[0].StudentNumber +'&nbsp&nbsp&nbsp'+ '成绩为:' + data[0][subject] + '<br>');
        }
        ScoreHandling.prototype.outputScore=function(){
            let _data=this.data;
            for(let stu of _data){
                stu.TotalScore=stu.Chinese+stu.Math+stu.English;
                var stuscore=(stu.TotalScore/3).toFixed(1);
                if(stuscore>=110){
                    stu.Comment='A';
                } else if(stuscore>=100){
                    stu.Comment='B';
                } else if(stuscore>=90){
                    stu.Comment='C';
                }else if(stuscore>=72){
                    stu.Comment='D';
                }else {
                    stu.Comment='E';
                }
        }
        console.log(_data);
        this.scoreSort(_data,'TotalScore','总成绩');
        this.scoreSort(_data,'Chinese','语文'); 
        this.scoreSort(_data,'Math','数学');
        this.scoreSort(_data,'English','英语');
        }
        var score=new ScoreHandling(data);
        score.outputScore();

 运行截图如下:

 

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值