if 语句,第一个条件的值在第二个条件的范围内,但它返回第一个条件

时间:2021-01-29 16:36:38

标签: javascript

我正在使用 C=0 抽样计划创建一个 QA 抽样计算器。 每当我输入任何数字并尝试它时,我提供的结果对应于不同范围的结果。

const sample = parseFloat(this.sampleSize)
const lot = parseFloat(this.lotSize)

if (aqlSelector.value == 0.010) {
    if (this.sampleSize > 0 || this.sampleSize <= 1200) {
        lotQty.innerText = 'All'
        console.log(sample)
        console.log(lot)
    } else if (this.sampleSize >= 1201) {
        lotQty.innerText = '1250'
    }
} 

Code after trying different approach Results I'm getting

整个项目的代码笔:https://codepen.io/cesar-higashi/pen/LYbPwaJ

2 个答案:

答案 0 :(得分:0)

您使用了错误的逻辑运算符 if (this.sampleSize > 0 || this.sampleSize <= 1200) 它应该是 if (this.sampleSize > 0 && this.sampleSize <= 1200)

使用您的 ||(或),对于每个大于 0 的值,它首先返回

答案 1 :(得分:0)

解决了!

事实证明,代码中的某个部分为长数字添加了逗号 (',') 以使其更易于阅读,这反过来又使它们成为 NaN。

一旦项目结束,我将更新代码笔。感谢所有花时间的人,非常感谢。