1
2
wheels = 2
wheels == 0 ? "Unknown Vehicle" : wheels <= 2 ? "Unicycle/Motorcyle/Scooter" : "Car/Truck"

Nested ternary operators provide a concise method to express if-elsif-else statements.

We set wheels = 2 then our nested ternary opertor evaluates whether wheels == 0, if so, it returns Unknown Vehicle, if not, it evaluates whehter wheels <= 2, if so, it returns Unicycle/Motorcycle/Scooter, if not, it returns Car/Truck.

Comments