using a data structure instead of if-else cascade