+ 2

Ternary operators with disjunction?

Is it possible to add disjunction in condition? I want to add an empty string besides null. https://code.sololearn.com/WC7S8dPpgi3Q/?ref=app

25th Oct 2017, 10:10 PM
Goran Mitic
Goran Mitic - avatar
3 Respostas
+ 12
Yes it's entirely possible to combine multiple conditions with conditional operator. However in this case only 1 condition is suffice to test for null or empty string as both evaluates to falsy in JavaScript. Hence, name ? name : 'Anonymous' P/S: When in doubt next time, you may experiment it by yourself. 😉
26th Oct 2017, 12:02 AM
Zephyr Koo
Zephyr Koo - avatar
+ 4
For multiple disjunction, check out this challenge I did: To calculate interest based on different amount input range: function interest(a) { return a>90000? a*0.05: a>50000? a*0.04: a>20000? a*0.03: a>5000? a*0.02:0; } https://code.sololearn.com/W6qZPtRnIFYt/?ref=app
26th Oct 2017, 12:21 PM
Calviղ
Calviղ - avatar
0
how to write single ternary operator using three variables in
31st Oct 2017, 1:50 AM
Aishwarya Viraktamath