'Javascript - How do I prevent a function from calling another function if none of the conditions are met?

I'm creating a tic tac toe game for class. Right now when the user makes their move, the computer turn function is activated, but I'm trying to stop the "computer" from making a move when the user meets the winning criteria. Could you please help me? Thanks

This is how my turn system works

function leaveMark(){
  let toes = document.querySelectorAll('img');
  let toesId = this.getAttribute('data-id');
  chosenToeId.push(toesId);
  takenId.push(toesId);
  userChoices.push(toesId);
  let chosenToe = chosenToeId[0];
  toes[chosenToe].setAttribute('src','img/tic-tac-toe/hammer.png');
  chosenToeId = [];
  userValidation();
  // setTimeout(computerTurn, 1000);
}

/////computer turn////////

function computerTurn(){
  let randomId = Math.floor((Math.random()*imgId.length));
  let randomIdString = randomId.toString();
  let toes = document.querySelectorAll('img');
  if (!takenId.includes(randomIdString)){
    toes[randomId].setAttribute('src','img/tic-tac-toe/boots.png');
    takenId.push(randomIdString);
    computerChoices.push(randomId);
  } else{
      computerTurn();
    }
    computerValidation();
  }

At first I called the computerTurn function when the user clicked on the board, but now I'm trying to link it to the winning logic of the game. But since my if statements are inside a forEach, I can't really call the computerTurn function from there. I also tried with a reassignment of variables but I think it won't work because of the scope of the forEach.

Thank you again

This is the winning logic.

function userValidation() {
  let nextTurn = false;
  let numberUser = userChoices.map(i=>Number(i));
  winningCombos.forEach((e) =>{
    let a = e[0];
    let b = e[1];
    let c = e[2];
    if (numberUser.includes(a) && numberUser.includes(b) && numberUser.includes(c)){ 
      console.log('user wins');
      
    } else if (takenId.length === imgId.length){
      console.log('This is a tie. Not bad, try again.');
      
    } else {
      nextTurn = true;
      
     
    }
  })
  if (nextTurn == true){
    setTimeout(computerTurn, 1000)
  }
}

  function computerValidation() {
    let numberComputer = computerChoices.map(i=>Number(i));
    winningCombos.forEach((e) =>{
      let a = e[0];
      let b = e[1];
      let c = e[2];
      if (numberComputer.includes(a) && numberComputer.includes(b) && numberComputer.includes(c)){
        console.log('Sorry, you lost. Try again!');
      } else if (takenId.length === imgId.length){
        console.log('This is a tie. Not bad, try again.');
      } else {
        messages.textContent = 'Your turn, user.'
      }
    });
  };


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source