JS Ternary functions with multiple conditions?

前端 未结 9 585
花落未央
花落未央 2020-12-31 04:44

I have been using a ternary operator in JavaScript to modify the value of an object based on user input. I have the following code, which runs as it should:

         


        
9条回答
  •  渐次进展
    2020-12-31 05:22

    Yes, you can use multiple condition in Ternary Operator. Hope this will help you.

    var x=20;
    var y = x<13 ? "Child" : x<20 ? "Teenage" : x<30 ? "Twenties" : "Old people";
    console.log(y);
    

提交回复
热议问题