I making a condition in javascript that if a value or b value is greater than 59 and c1, c2, c3, c4 any of these are greater than 21 than my condition will be true. It's working fine but when I entering a value 50 b value 30 and c1 value 25 it is going to else statement.
Here is the code:
if((a > 59) || (b > 59) && (c1 > 21) && (c2 > 21) && (c3 > 21) && (c4 > 21)){
total = a + b + c1 + c2 + c3 + c4;
}
else {
}
Can you guyz help me out how to fulfill my conditions?
bis 30, then(b > 59)isfalse, also(a > 59)isfalsesinceais 50 - why are you surprised you end up in theelsebranch?if((a > 59) || (b > 59) && ...should be:if((a > 59 || b > 59) && ...This will help you understand your conditions more easily and it will create more accurate execution.Mathcomes in handy:Math.max(a, b) > 59 && Math.max(c1, c2, c3, c4) > 21- in case you really meant to check all cX values for a minimum of 21:Math.max(a, b) && Math.min(c1, c2, c3, c4) > 21