用二维数组存一组学生的成绩,输出总成绩的是谁和分数,输出语文第一名是的谁和成绩

<!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>

 

效果图 ↓

 

posted @ 2017-08-26 17:08  背壳前进的牛  阅读(521)  评论(0编辑  收藏  举报