Tic Tac Toe Glitching

I am trying to get my tic tac toe game to place a random O for each X. (If you test it choose to play x because the o doesn’t work right now.) It works about 50 percent of the time, if you test it out a few times you will see what I mean. If someone is brave enough to look through my over complicated and mess of a code to help me figure out this glitch I would very much appreciate it.

Ok I will start with that. When I run it, it will tell me when I have won, but somtimes the O will no happen.
Do you have any advice for making a repetitive function when every case has different variables in it? For instance, how could I have repetition when for case 2 the index is different as well as the variable that is coming true. For instance, in case 2, topMiddleo is becoming true, but for case 3, it’s topRighto.

Also thank you so much for your help. you’ve been such a great help throughout all of my projects.