how to turn off iphone 4 when the off button does not work

The power button on top does not work and I want to turn my phone off and back on. How is this done without the power button on top not working on the iphone 4?
Welcome to iMore! Go to Settings > General > Accessibility, and toggle the AssistiveTouch switch ON. This will put a software power button on your screen that you can use to restart your iPhone. This will place a circle software-based button on your screen. Tap it, select Device, long press on Lock Screen, then swipe the slider to the right to power off your device. In order to turn your iPhone back in you'll need to plug it into a charger.

Original thread: https://forums.imore.com/threads/how-to-turn-off-iphone-4-when-the-off-button-does-not-work.369295/