The Employee has a method that determines if they have enough money to buy something.
Note: For this example I will be using an instance of an object assigned to a variable to make the code more readable. We will cover this in other articles.
And there is a method call that checks the return and if it's true, they buy the item.
Our Employee Sam, however, has loose moral and wouldn't be opposed to stealing an item if he doesn't have enough money. So we will use the same conditional, but have Sam steal instead of buy.
When we step through the Purchasable method we can see that Sam doesn't have enough money and the hasEnoughMoney method will return false.
We have a bit of a problem, though, because since the method is returning false, the conditional will evaluate to false and the Steal method will be skipped over.
To fix this we need to put a ! operator in front of the call to Purchasable.
This operator will take whatever the return from Purchasable and make it its opposite. In this example, Purchasable returns false and the ! operator will make it true. This makes the conditional evaluate to true because the opposite of false...is true.
In plain English this would be the equivalent of saying "If the item is not purchasable, then steal it."
Now when we run the application, even though the Purchasable method returns false, we can force the conditional to be 'true' by making it its opposite.