Functions

ifs

New

Returns the val­ue that cor­re­sponds to the first true con­di­tion. This can be used as an alter­na­tive to mul­ti­ple nest­ed if() statements.

Category
Conditional
Syntax
ifs(condition, ifTrue, condition2, ifTrue2, ..., else)
ifs(
    1 + 1 == 1, 1, 
    1 + 1 == 2, 2, 
    3
)ifs(

    /* Check if 1 + 1 equals 1, and if it does display 1 */
    1 + 1 == 1, 1,

    /* Otherwise check if 1 + 1 equals 2, and if it does display 2 */
    1 + 1 == 2, 2,

    /* Otherwise display 3 */
    3
    
)
=
2