function loadBoard(){
    var i = 0; // reset before drawing
    boardIsLoaded = true;
    var grid = document.createElement('table');
    var sizeOfGrid = 3;
    
    var column = 0;
    var row = 0;
    while (row < sizeOfGrid) {
        // add new row
        column = 0;
        var newRow = document.createElement('tr');
        grid.appendChild(newRow);
        while (column < sizeOfGrid) { // iterate through 3 columns for 3x3 board
            // add cell current column
            var newCell = document.createElement('td');
            formatCells(newCell, row, column);
            newCell.classList.add('column_' + column, 'row_' + row);

            // left diagonal 
            if (row == column) newCell.classList.add('left_diag_0');

            // right diagonal
            var rightDiagonalPos = sizeOfGrid - row - 1;
            if (column == rightDiagonalPos) newCell.classList.add('right_diag_1');
            newCell.index = i;
            newRow.appendChild(newCell);
            cellArray.push(newCell);
            i++;
            // set on click event to place marker
            newCell.addEventListener('click', onClick);
            console.log("Adding column: " + column);
            column++; // next column
        }
        drawOnTo(grid);
        console.log("Adding row: " + row);
        row++; // next row
    }
    document.getElementById("gameMode").style.visibility = "visible";
    document.getElementById("backToMainMenu").style.visibility= "visible"; 
    document.getElementById('playArea').appendChild(grid);
}
/*
 * dynamically create a grid and add cells to it
 */
dynamically create a grid and add cells to it
dynamically create a grid and add cells to it
function loadBoard(){
    var i = 0; 
    boardIsLoaded = true;
    var grid = document.createElement('table');
    var sizeOfGrid = 3;
    var column = 0;
    var row = 0;
    while (row < sizeOfGrid) {
        column = 0;
        var newRow = document.createElement('tr');
        grid.appendChild(newRow);
        while (column < sizeOfGrid) { 
            var newCell = document.createElement('td');
            formatCells(newCell, row, column);
            newCell.classList.add('column_' + column, 'row_' + row);
            if (row == column) newCell.classList.add('left_diag_0');
            var rightDiagonalPos = sizeOfGrid - row - 1;
            if (column == rightDiagonalPos) newCell.classList.add('right_diag_1');
            newCell.index = i;
            newRow.appendChild(newCell);
            cellArray.push(newCell);
            i++;
            newCell.addEventListener('click', onClick);
            console.log("Adding column: " + column);
            column++; 
        }
        drawOnTo(grid);
        console.log("Adding row: " + row);
        row++; 
    }
    document.getElementById("gameMode").style.visibility = "visible";
    document.getElementById("backToMainMenu").style.visibility= "visible"; 
    document.getElementById('playArea').appendChild(grid);
}
function loadBoard ( ) { var i = 0 ; boardIsLoaded = true ; var grid = document . createElement ( 'table' ) ; var sizeOfGrid = 3 ; var column = 0 ; var row = 0 ; while ( row < sizeOfGrid ) { column = 0 ; var newRow = document . createElement ( 'tr' ) ; grid . appendChild ( newRow ) ; while ( column < sizeOfGrid ) { var newCell = document . createElement ( 'td' ) ; formatCells ( newCell , row , column ) ; newCell . classList . add ( 'column_' + column , 'row_' + row ) ; if ( row == column ) newCell . classList . add ( 'left_diag_0' ) ; var rightDiagonalPos = sizeOfGrid - row - 1 ; if ( column == rightDiagonalPos ) newCell . classList . add ( 'right_diag_1' ) ; newCell . index = i ; newRow . appendChild ( newCell ) ; cellArray . push ( newCell ) ; i ++ ; newCell . addEventListener ( 'click' , onClick ) ; console . log ( "Adding column: " + column ) ; column ++ ; } drawOnTo ( grid ) ; console . log ( "Adding row: " + row ) ; row ++ ; } document . getElementById ( "gameMode" ) . style . visibility = "visible" ; document . getElementById ( "backToMainMenu" ) . style . visibility = "visible" ; document . getElementById ( 'playArea' ) . appendChild ( grid ) ; }
dynamically create a grid and add cells to it
dynamically create a grid and add cells to it
// reset before drawing // add new row // iterate through 3 columns for 3x3 board // add cell current column // left diagonal  // right diagonal // set on click event to place marker // next column // next row