Multiple conditions in an if clause

后端 未结 9 1054
醉梦人生
醉梦人生 2021-02-02 06:44

If I have an if statement that needs to meet these requirements:

if(cave > 0 && training > 0 && mobility > 0 && sleep > 0)
         


        
9条回答
  •  粉色の甜心
    2021-02-02 07:19

    Why you are looking for solution?

    Your question looks like best and simple answer, i recommend it. We have multiple solutions for this. Below one is that.

    JSBin for .every()

    Achieve it by using .every function

    var flag = [cave, training, mobility, sleep].every(function(val) {
         return val > 0;
      });
    
    if(flag) {
      alert('All the elements are greater than Zero');
    }
    

提交回复
热议问题