简体   繁体   English

为什么不执行if语句

[英]Why isn't if statement executed

There is a task to count the number of words "not_available", if 12 then send 1, if at least one of them is "available" send 0有一个任务是统计单词“not_available”的数量,如果是12则发送1,如果其中至少一个是“available”则发送0

Below is a sample code that still sends 0 even if the number of "not_available" = 12下面是一个示例代码,即使“not_available”的数量 = 12,它仍然发送 0

What was I wrong about?我做错了什么?

var Count_available = (rootObj.match(/AVAILABLE/g) || []).length
var Count_unavailable = (rootObj.match(/NOT_AVAILABLE/g) || []).length

if (Count_available >= 1) {
  var jsondata = {
    "type": "SberLogistic.Availability",
    "series": [{
      "timeseriesId": "custom:syntheticmonitors.availability",
      "dimensions": {
        "config_id": "CI02874375"
      },
      "dataPoints": [
        [Number(new Date()), 1]
      ] //send 1

    }]
  }
} else if (Count_unavailable == 12) {
  var jsondata = {
    "type": "SberLogistic.Availability",
    "series": [{
      "timeseriesId": "custom:syntheticmonitors.availability",
      "dimensions": {
        "config_id": "CI02874375"
      },
      "dataPoints": [
        [Number(new Date()), 0]
      ] //send 0

    }]
  }
};

If at least 1 is available, it will return without checking the else if.如果至少有 1 个可用,它将返回而不检查 else if。

Reverse the order, then it will check unavailable before available.颠倒顺序,然后它会在可用之前检查不可用。

    if (Count_unavailable == 12) {
    ...
    } else if (Count_available >= 1) {
    ...
    };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM