【问题标题】:ERROR: expected declaration or statement within else if statements错误:else if 语句中的预期声明或语句
【发布时间】:2018-06-02 06:38:15
【问题描述】:
if (shirtWidth >= 18 && shirtWidth > 29)  (shirtLength >29) && (shirtSleeve > 8.38); {
    console.log("S");    
    } else if (shirtWidth >= 19 && shirtWidth == 22)  (shirtLength == 29) && (shirtSleeve > 8.13 && shirtSleeve < 8.38); {
    console.log("M");    
    } else if (shirtWidth >= 21 && shirtWidth == 23)  (shirtLength === 30) && (shirtSleeve > 8.38 && shirtSleeve == 8.87); {
    console.log("L");    
    } else if (shirtWidth <22 && shirtWidth == 25)  (shirtLength === 31) && (shirtSleeve < 8.63 && shirtSleeve == 9.62); {
    console.log("XL");    
    } else if (shirtWidth < 24 && shirtWidth == 29)  (shirtLength === 34) && (shirtSleeve < 9.63 && shirtSleeve == 10.12); {
    console.log("2XL");    
    } else if (shirtWidth < 26  && shirtWidth == 23)  (shirtLength === 30) && (shirtSleeve < 10.13 && shirtSleeve ==12.00); {
    console.log("3XL");    
    }

如果你还不能说,我对 JavaScript 很陌生。使用我的 else if 语句,我似乎无法找到解决此错误的方法。

【问题讨论】:

    标签: javascript expression declaration


    【解决方案1】:

    修改你的代码,你做错了

    if ((shirtWidth >= 18 && shirtWidth > 29) || (shirtLength >29 && shirtSleeve > 8.38) ){
          console.log("S");    
    } else if( (shirtWidth >= 19 && shirtWidth == 22) || (shirtLength == 29 && shirtSleeve > 8.13 && shirtSleeve < 8.38)){
        console.log("M");    
    } else if ((shirtWidth >= 21 && shirtWidth == 23) || (shirtLength === 30 && shirtSleeve > 8.38 && shirtSleeve == 8.87)){
        console.log("L");    
    } else if ((shirtWidth <22 && shirtWidth == 25) || (shirtLength === 31 && shirtSleeve < 8.63 && shirtSleeve == 9.62)) {
        console.log("XL");    
    } else if ((shirtWidth < 24 && shirtWidth == 29) || (shirtLength === 34 && shirtSleeve < 9.63 && shirtSleeve == 10.12)) {
        console.log("2XL");    
    } else if((shirtWidth < 26  && shirtWidth == 23) || (shirtLength === 30 && shirtSleeve < 10.13 && shirtSleeve ==12.00)) {
        console.log("3XL");    
    }
    

    【讨论】:

    • 您在最后一个条件中缺少else if
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 2013-06-18
    • 1970-01-01
    • 2018-08-30
    • 2020-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多