How to fulfill 2 or more conditions, and not one in a shortened version of if?

  • 0
    Kind. Is it possible to fulfill 2 or more conditions in a shortened version of if?
    For example:
    i > 5 ? a = 5, console.log(i) : b = 4, console.log(i)
    JavaScript Anonymous, Jun 19, 2019

  • 3 Answers
  • 0
    The question is incorrect.

    To avoid looking for a comment:

    I mean how to make it so that after the condition I can perform 2 actions, and not one? For example age & lt; 3? 'Hello how are you?' : 'Hai', 'Bai'


    condition? (..., ..., ...): (...)
    Anonymous

  • 0
    let message = (age < 3) ? 'Здравствуй, малыш!' :
    (age < 18) ? 'Привет!' :
    (age < 100) ? 'Здравствуйте!' :
    'Какой необычный возраст!';


    https://learn.javascript.com/ifelse
    Anonymous

  • 0
    This is not a shortened version, but a ternary operator.

    Do one ternary operator nested within another.

    But this is often not recommended.

    There is no benefit, and the readability of the code deteriorates.
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!