How to switch between two players in tic tac toe game?

When i call the getActivePlayer method, it returns “player one”, and when i call switchPlayerTurn, it returns “player two”, however when i call getActivePlayer or even try to console log activePlayer after switching the turns, it still returns “player one”.

Ive tried using an if…else statement opposed to a ternary operator. Ive tried writing return statements in different parts of the if…else statement. Ive also searched these forums and while there are posts that are very similar to mine, ive already tried their solutions. Could it be an issue of scope? The switchPlayerTurn method is contained within a gaemController function, however, the activePlayer variable should be accessible from the method and should be able to change its value, correct?

I wrote a simple version at the bottom of my code changing the variable x and that works, but when i apply that above, it doesnt change anything.

function gameController(
    playerOneName = "Player One",
    playerTwoName = "Player Two"
) {
    const players = [
        {
            name : playerOneName,
            token : 1
        },
        {
            name : playerTwoName,
            token : 2
        }
    ];

    let activePlayer = players[0];


    const switchPlayerTurn = () => {  
        activePlayer = activePlayer === players[0] ? players[1] : players[0];
        console.log(activePlayer);
    };

    /*  if...else statement alternative 

    function switchPlayer() {
        if (activePlayer === players[0]) {
           activePlayer = players[1];
        } else if (activePlayer === players[1]) {
            activePlayer = players[0];
        }

    };

    */

    const getActivePlayer = () => activePlayer;

    const printNewRound = () => {
        gameBoard.printBoard();
        console.log(`${getActivePlayer().name}'s turn'`);
    };

    const playRound = (row, column) => {
        gameBoard.playMove(row, column, getActivePlayer().token);
        switchPlayer();
        printNewRound();
    }

    return {
        activePlayer,
        switchPlayerTurn,
        getActivePlayer,
        players,
        printNewRound,
        playRound
    };            
}

const gc = gameController();
console.log(gc.getActivePlayer());
gc.switchPlayerTurn();
console.log(gc.getActivePlayer());
// test
let x = 1;
function switchX() {
    if (x === 1) {
        x = 2;
    } else if (x === 2) {
        x = 1;
    } 
    console.log(x);
}
switchX();
switchX();