So as a first step, you should always look to reduce your code to its essential "essence". This allows you to have a better view of the larger picture. It's important because that's how you'll find patterns to build your classes.
I removed the unused global. I also restructured your code so that we could see an initial state when the function started. I came to notice that you reused the same bit of code for your response. I moved that to its own function.
Make sure to test it. I might have inserted a bug. I just edited the file directly on GitHub :joy:
So as a first step, you should always look to reduce your code to its essential "essence". This allows you to have a better view of the larger picture. It's important because that's how you'll find patterns to build your classes.
I removed the unused global. I also restructured your code so that we could see an initial state when the function started. I came to notice that you reused the same bit of code for your response. I moved that to its own function.
Make sure to test it. I might have inserted a bug. I just edited the file directly on GitHub :joy: