const keys = ['A','B','C','D','Default'],
range = [90,80,70,60,0];
const judge = (score) => {
const len = range.length;
for(let i = 0;i < len;i++){
if(score >= range[i]){
return keys[i];
}
}
}
const fun = {
'A':() => '优秀',
'B':() => '良好',
'C':() => '中等',
'D':() => '及格',
'Default':() => {'不及格'},
}
console.log(fun[judge(100)]())
if、switch
int score = 90;
if(score >= 90){
Text = "优秀";
}
else if (score >= 80 && score < 90) {
Text = "良好";
}else if(score >=70 && score<80){
Text = "中等";
}else if (score >=60 && score<70){
Text = "及格";
}else{
Text = "不及格";
}
switch(score / 10){
case 10:
Text = "优秀";break;
case 9:
Text = "优秀";break;
case 8:
Text = "良好";break;
case 7:
Text = "中等";break;
case 6:
Text = "及格";break;
default:
Text = "不及格";break;
}
|