ternary operator solution to exercise 4