function makeMove(button, buttonNo) {

    var row = buttonNo % 7 === 0 ? Math.floor(buttonNo / 7) - 1 : Math.floor(buttonNo / 7);
    var col = buttonNo % 7 === 0 ? 6 : (buttonNo % 7) - 1;

    if (playerNumber === 1) {

        button.classList.add("btn-player-1");


        filledGrid[row][col] = 1;
        filledCells++;


        if (playerWon(row, col, 1) === true) {





            win.play();
            swal({
                    title: "GREEN WINS",
                    text: "Press Ok To Play Again",
                    icon: "success",
                    buttons: true,
                    Mode: true,
                })
                .then((willDelete) => {
                    if (willDelete) {
                        resetBoard();
                    }
                });
        }

        // Update the player
        playerNumber = 2;
        playerType.textContent = "Player - 2";

    } else {

        button.classList.add("btn-player-2");


        filledGrid[row][col] = 2;
        filledCells++;

        if (playerWon(row, col, 2) === true) {
            win.play();
            swal({
                    title: "RED WINS",
                    text: "Press Ok To Play Again",
                    icon: "success",
                    buttons: true,
                    Mode: true,
                })
                .then((willDelete) => {
                    if (willDelete) {
                        resetBoard();
                    }
                });
        }

        // Update the player
        playerNumber = 1;
        playerType.textContent = "Player - 1";

    }

    // If all the cells has been filled

    if (filledCells === 42) {
        lost.play();
        swal({
                title: "Draw",
                text: "Press Ok To Play Again",
                icon: "error",
                buttons: true,
                dangerMode: true,
            })
            .then((willDelete) => {
                if (willDelete) {
                    resetBoard();
                }
            });
        return;
    }

    // Disable the button is the move is made
    setTimeout(function() {
        button.disabled = true;
    }, 10);

}
// Function to Make Move on the passed button and disable it
Function to Make Move on the passed button and disable it
Function to Make Move on the passed button and disable it
function makeMove(button, buttonNo) {
    var row = buttonNo % 7 === 0 ? Math.floor(buttonNo / 7) - 1 : Math.floor(buttonNo / 7);
    var col = buttonNo % 7 === 0 ? 6 : (buttonNo % 7) - 1;
    if (playerNumber === 1) {
        button.classList.add("btn-player-1");
        filledGrid[row][col] = 1;
        filledCells++;
        if (playerWon(row, col, 1) === true) {
            win.play();
            swal({
                    title: "GREEN WINS",
                    text: "Press Ok To Play Again",
                    icon: "success",
                    buttons: true,
                    Mode: true,
                })
                .then((willDelete) => {
                    if (willDelete) {
                        resetBoard();
                    }
                });
        }
        playerNumber = 2;
        playerType.textContent = "Player - 2";
    } else {
        button.classList.add("btn-player-2");
        filledGrid[row][col] = 2;
        filledCells++;
        if (playerWon(row, col, 2) === true) {
            win.play();
            swal({
                    title: "RED WINS",
                    text: "Press Ok To Play Again",
                    icon: "success",
                    buttons: true,
                    Mode: true,
                })
                .then((willDelete) => {
                    if (willDelete) {
                        resetBoard();
                    }
                });
        }
        playerNumber = 1;
        playerType.textContent = "Player - 1";
    }
    if (filledCells === 42) {
        lost.play();
        swal({
                title: "Draw",
                text: "Press Ok To Play Again",
                icon: "error",
                buttons: true,
                dangerMode: true,
            })
            .then((willDelete) => {
                if (willDelete) {
                    resetBoard();
                }
            });
        return;
    }
    setTimeout(function() {
        button.disabled = true;
    }, 10);
}
function makeMove ( button , buttonNo ) { var row = buttonNo % 7 === 0 ? Math . floor ( buttonNo / 7 ) - 1 : Math . floor ( buttonNo / 7 ) ; var col = buttonNo % 7 === 0 ? 6 : ( buttonNo % 7 ) - 1 ; if ( playerNumber === 1 ) { button . classList . add ( "btn-player-1" ) ; filledGrid [ row ] [ col ] = 1 ; filledCells ++ ; if ( playerWon ( row , col , 1 ) === true ) { win . play ( ) ; swal ( { title : "GREEN WINS" , text : "Press Ok To Play Again" , icon : "success" , buttons : true , Mode : true , } ) . then ( ( willDelete ) => { if ( willDelete ) { resetBoard ( ) ; } } ) ; } playerNumber = 2 ; playerType . textContent = "Player - 2" ; } else { button . classList . add ( "btn-player-2" ) ; filledGrid [ row ] [ col ] = 2 ; filledCells ++ ; if ( playerWon ( row , col , 2 ) === true ) { win . play ( ) ; swal ( { title : "RED WINS" , text : "Press Ok To Play Again" , icon : "success" , buttons : true , Mode : true , } ) . then ( ( willDelete ) => { if ( willDelete ) { resetBoard ( ) ; } } ) ; } playerNumber = 1 ; playerType . textContent = "Player - 1" ; } if ( filledCells === 42 ) { lost . play ( ) ; swal ( { title : "Draw" , text : "Press Ok To Play Again" , icon : "error" , buttons : true , dangerMode : true , } ) . then ( ( willDelete ) => { if ( willDelete ) { resetBoard ( ) ; } } ) ; return ; } setTimeout ( function ( ) { button . disabled = true ; } , 10 ) ; }
Function to Make Move on the passed button and disable it
Function to Make Move on the passed button and disable it
// Update the player // Update the player // If all the cells has been filled // Disable the button is the move is made