javascript 基础知识整理 博客分类: javascript javascriptif.elsefor循环
程序员文章站
2024-03-08 08:01:39
...
编写if-else条件语句
if(score>90) { console.log('成绩及格'); } else { console.log('成绩不及格'); }
求各个分数段之前的学生个数
var all_math_scores = [143,135,139,148,135,133,143,142,139,142]; var count_A = 0;//存储成绩140分以上的学生的个数 var count_B = 0;//存储成绩在130~140分之间的学生的个数 var count_C = 0;//存储成绩在130分以下的学生的个数 for(var i = 0 ;i <all_math_scores.length;i++) { if(all_math_scores[i]>140) { count_A = count_A + 1; } else if(all_math_scores[i]>130) { count_B = count_B + 1; } else { count_C = count_C + 1 } }
求此学生的三科成绩的最高分,并赋值给变量highest_score
var all_scores = {'杨璐':[131,143,144], '王雪':[131,135,144], '韩林霖':[127,139,142], '沙龙逸':[123,148,136], '李鉴学':[126,135,140], '韩雨萌':[129,133,138], '刘帅':[116,143,140], '康惠雯':[114,142,139], '刘钰婷':[115,139,135], '林世博':[116,142,129]}; var highest_score ; var stu_name = '李鉴学'; var arr_scores = all_scores[stu_name]; highest_score = arr_scores[0]; for (var i = 0;i<arr_scores.length;i++) { if(highest_score<arr_scores[i]) { highest_score = arr_scores[i]; } }