Adding ternary operator in place of if statement