If I have an if statement that needs to meet these requirements:
if(cave > 0 && training > 0 && mobility > 0 && sleep > 0)
>
As some have stated there is nothing wrong in having multiple simple conditions in an if statement, however I would consider changing the formatting into:
if ( cave > 0
&& training > 0
&& mobility > 0
&& sleep > 0 )
Alternatively I would change the from using these variables as integers, into bool variables, i.e. isCave
, hasTraining
, or similar, and then set the proper bool closer to where your code defines the different properties (Edit: And possibly return early if it is false, to prevent further unneccessary calculations). This would simplify your if statement to the latter in the next code block, which in addition shows a variant which can be used if the conditions becomes slightly more complex or you would like to ease the reading of the if statement:
var isCave = cave > 0; # What does cave > 0 mean?
var hasTraining = training > 0;
var isMobile = mobility > 0;
var isNotSleeping = sleep > 0; # What does sleep > 0 indicate? Unclear
if (isCave && hasTraining && isMobile && isNotSleeping ) {
// Do your thing
}
In other words, the multiple conditions in your if statement is not your biggest code smell, I would shift my focus to giving your variables better names clearly indicating what the value indicates. This would improve reading and understanding of your code, way more than some strange syntax to avoid multiple if conditions.