I understand what all the code is doing, as I've done this and much more previously.
Unfortunately you seem to have partly missed the point of this exercize...
It seems to me that you're supposed...