使用分级开关

问题描述 投票:-1回答:1

我试图使用开关输出成绩但是有一个错误idk为什么它不起作用,它向我显示了默认消息我检查了:坏了,但我仍然不知道错误所以我需要一些帮助谢谢

<script>
    var grade=0;
    
    grade=window.prompt("Enter your grade");
    
    switch(grade)
        {
             case grade>= 95:
                document.write("You got A+");
                break;
                
            case grade<95 && grade>= 90:
                document.write("You got A");
                break;   
            
            case grade<90 && grade>=85:
                document.write("You got A-");
                break;
                
            case grade<85 && grade>=80:
                document.write("You got B+");
                break;
                
            case grade<80 && grade>=75:
                document.write("You got B");
                break;
            
            case grade<75 && grade>=70:
                document.write("You got B-");
                break;
                
            case grade<70 && grade>=65:
                document.write("You got C+");
                break;
                
            case grade<65 && grade>=60:
                document.write("You got C");
                break;
                
            case grade<60 && grade>=55:
                document.write("You got C-");
                break;
                
            case grade<55 && grade>=50:
                document.write("You got D");
                break;
                
            case grade<50:
                document.write("You FAILED");  
                break;
                
             default:
                document.write("Wrong Number"); 
        }
</script>

消息,我需要一些帮助谢谢

javascript switch-statement
1个回答
0
投票

由于要使用布尔值,因此应使用if-else

© www.soinside.com 2019 - 2024. All rights reserved.