JSFiddle - React, Tailwind, and code Playground

by Chris

HTML

<body onload="createDivs()">
  <p id="demo"></p>

CSS

div {
            border: solid 2px black;
            width: 300px;
            height: 300px;
            float: left;
            border-right: none;
            border-top: none;
            overflow: hidden;
        }

JavaScript

var alternate = 'O';
        var count = 0;
        
        function createDivs() {
            var t;
            var ai;
            var trackId =[];
            
            for (i=0; i<9; i++) {
                var d = document.createElement("DIV");
                document.body.appendChild(d);
                
                d.onclick = function() {
                    if (count > 8) { 
                        return
                    }
                    
                    var xP = document.createElement("P");
                    var oP = document.createElement("P");
                    
                    var childCount = "childID"+count;
                    
                    xP.setAttribute("id", childCount);
                    
                    trackId.push(childCount);
                    /*
                    alert(trackId.toString());
                    */
                    
                    count++;
                    oP.setAttribute("id", "childID"+count);
                    count++;
                    
                    if (alternate == 'O') {
                        t = document.createTextNode("X");
                        alternate = 'X';
                    xP.appendChild(t);
                    this.appendChild(xP);
                    this.onclick = function() {};
                    
                    /*
                    for (aa = 0; aa < 9; aa++) {
                        var zed = "D"+aa;
                        var bb = document.getElementById(zed).innerText;
                        while (bb == 'X' || bb == 'O') {
                            zed = Math.floor(Math.random() * 9);
                        } 
                    }
                    */
                        
                    if (count > 9) {
                    }else{
                        
                    while (zed == 'X' || zed == 'O') {
                        var r = Math.floor(Math.random() * 9);
                        var zed...