js交换案例等级率

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

我需要编写js(仅在switch中)工作,该工作会将学生的成绩转换为单词,exp如果学生的成绩在75到84之间,那会写的很好,问题是它仅通过了开关的第二部分,需要您的帮助,该怎么做才是正确的,谢谢!


  var grade = (prompt("Enter your grade"));

  switch (Math.floor(grade / 10)) 
        {
            case 10:
                if  ((grade > 94)&&(grade<=100))
                    document.write(+grade + " mezuiam"); break;

            case 9:
                if ((grade>85) && (grade<=93))
                    document.write(+grade + " tov meod"); break;

            case 8: if  ((grade > 75 && grade <= 84))
                document.write(+grade + " tov"); break;

            case 7: if ((grade > 65) && (grade <= 74))
                document.write(+grade + " kimat tov"); break;

            case 6: if ((grade > 55 && grade <= 64))
                document.write(+grade + " maspik"); break;

            case 5: if (grade <= 54)
                document.write(+grade + " bilti maspik"); break;

            case 4: if (grade <= 54)
                document.write(+grade + " bilti maspik"); break;

            case 3: if (grade <= 54)
                document.write(+grade + " bilti maspik"); break;

            case 2: if (grade <= 54)
                document.write(+grade + " bilti maspik"); break;

            case 1: if (grade <= 54)
                document.write(+grade + " bilti maspik"); break;

            case 0: if (grade <= 54)
                document.write(+grade + " bilti maspik"); break;

        }


javascript switch-statement
2个回答
0
投票
var grade = (prompt("Enter your grade"));

switch (Math.floor(grade / 10)) {
    case 10:
        if (grade > 94 && grade <= 100)
            document.write(+grade + " mezuiam");
        break;

    case 9:
        if (grade > 85 && grade <= 93)
            document.write(+grade + " tov meod");
        break;

    case 8:
        if ((grade > 75 && grade <= 84))
            document.write(+grade + " tov");
        break;

    case 7:
        if (grade > 65 && grade <= 74)
            document.write(+grade + " kimat tov");
        break;

    case 6:
        if (grade > 55 && grade <= 64)
            document.write(+grade + " maspik");
        break;

    case 5:
        if (grade <= 54)
            document.write(+grade + " bilti maspik");
        break;

    case 4:
        if (grade <= 54)
            document.write(+grade + " bilti maspik");
        break;

    case 3:
        if (grade <= 54)
            document.write(+grade + " bilti maspik");
        break;

    case 2:
        if (grade <= 54)
            document.write(+grade + " bilti maspik");
        break;

    case 1:
        if (grade <= 54)
            document.write(+grade + " bilti maspik");
        break;

    case 0:
        if (grade <= 54)
            document.write(+grade + " bilti maspik");
        break;
    default:
        break;
}

0
投票

您可以直接为100之外的等级添加条件,无需将其转换为10磅秤。您的代码可以简化如下:

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