wondering what the best way of adding a function without breaking the code

The best way to do it is first you make an attempt. Then we help you get it right.

So what function? What's it doing? I can't see one anywhere in that code (which is already broken so that's not a good start).

Steve