Problem with TicTacToe

Hi,
Anyone could help me?
why this code does not work?
I have not response after running tictactoe() function

function showBoard(b){
    let k=1;
    let board =``;
    for (let i = 0; i <11; i++) {
        board +=b[i];
    	if ((i+1)%3 == 0 )board +=`\n`
        }
    return board;
}
function getUserInput(board, currentPlayer ){
    let b = showBoard(board);//11
    return //+prompt(`{b} \n Player ${currentPlayer}, please enter a field on the board(1-9):  `);
}
function isMoveValid(step, board){
    if (board[step-1] == 'X' || board[step-1] == 'O')   return false;
    if (step == 1 ||
        step == 2 ||
        step == 3 ||
        step == 4 ||
        step == 5 ||
        step == 6 ||
        step == 7 ||
        step == 8 ||
        step == 9   ) {return true}

    return false;
}
function hasLastMoverWon(gameBoard, lastMove) {
    let winnerCombos = [
        [0, 1, 2], 
        [3, 4, 5], 
        [6, 7, 8],
        [0, 3, 6],
        [1, 4, 7], 
        [2, 5, 8],
        [0, 4, 8], 
        [2, 4, 6]
        ];
        for (let [i1, i2, i3] of winnerCombos) {
            if (gameBoard[i1] === gameBoard[i2] && 
                gameBoard[i1] === gameBoard[i3] 
               ) {
                return true;
            }
    	}
    return false;}
function isBoardFull(board){
    if(board[0] == 1 ||
       board[1] == 2 ||
       board[2] == 3 ||
       board[3] == 4 ||
       board[4] == 5 ||
       board[5] == 6 ||
       board[6] == 7 ||
       board[7] == 8 ||
       board[8] == 9  ) return false;
     return true;
}
function isGameOver(gameBoard, currentPlayerSymbol, playersSymbols){
    if (hasLastMoverWon(gameBoard, currentPlayerSymbol) == true){
        console.log(`The Winner is player ${currentPlayerSymbol}, Game Over`);
    }
    else if ( isBoardFull(gameBoard)) {
        console.log("The game board is full\n Draw\n Game Over")
    }
    else return false
}
function makeMove(board, cP){
    let step = 0;
    //clone the gameBoard before placing moves on it
    const newGameBoard = [...board];
     do{ 
         step = getUserInput(board, cP);
     }while( isMoveValid(step, board) == true );
     const boardIndex = step-1;
     newGameBoard[boardIndex] = cP;
    return newGameBoard;
 }  
function tictactoe(){
    // STATE SPACE
    let b = '123456789';  
    let currentPlayerSymbol = 0;
    //Computations
    do {   currentPlayerSymbol = currentPlayerSymbol === 'X'? 'O' : 'X';
           b = makeMove(b, currentPlayerSymbol)
    }while ( !isGameOver(b, currentPlayerSymbol) )    
    }
1 Like

are you abel to post a screenshot of the error thst your getting in thr console

thanks for your answer.
I run the tictactoe() and nothing happens.

1 Like

can you explain a little more. the best way to do this is go to the function that is called when you click the button that runs tictactoe() and console.log() different things eventually you will see an error output in your dev tools. can you do this and take a screen shot of the console in the dev tools it will make it eaisieer for me to see