Solution

This looks ugly because I didn't use a method for the if statement
calculations. It works, though.