shortHand if else-if and else statement

后端 未结 2 375
迷失自我
迷失自我 2020-12-16 03:03

I have nested if else statements, which I added below in two statements, Instead of having a lot of lines I am looking to shorthand it.

Can anyone help me out.

2条回答
  •  清酒与你
    2020-12-16 03:42

    Statement : 1 can be written as,

    abc = (a !== -1 && b!== -1) ? "hai" : (c !== -1 && d!== -1) ? "hello" : "hurray";
    

    So based on this try to write your own code for the statement 2 [Hint : use switch for that]

提交回复
热议问题