rewriting code as conditional state ment using if else