Modified the attack() method to use ternary operators.