【JavaScript】用Switch实现成绩等级判断

let score = prompt("请输入成绩:");//输入成绩
let  a = parseInt(score / 10);//将字符串转换为数字
switch (a) {
    case 6:
        console.log(`成绩为${score},成绩等级为D`);
        break;
    case 7:
        console.log(`成绩为${score},成绩等级为C`);
        break;
    case 8:
        console.log(`成绩为${score},成绩等级为B`);
        break;
    case 9:
        console.log(`成绩为${score},成绩等级为A`);
        break;
    default:
        console.log(`成绩为${score},成绩等级为E`);
        break;
}

 

posted @ 2021-05-16 09:45  木子欢儿  阅读(1550)  评论(0编辑  收藏  举报