I'm making a tic-tac-toe game, my problem is that the game function doesn't wait for the user to choice where he want to play his move, it just run the (gameOver) function immediatly after I press start game button.
can anyone tell me what is wrong with my codes and help me to fix it ?
```
const start = document.getElementById('start');
const table = document.getElementById('table');
places = ["one", "two", "three", "four", "five", "six", "seven", 'eight', "nine"];
let move = 0;
start.addEventListener('click', function(){
startGame();
});
function startGame(){
console.log("Game started");
user();
}
function gameOver(){
console.log("Game Over");
}
function computer(){
let index = places[Math.floor(Math.random() * places.length)];
let pos = document.getElementById(index);
if (/[1-9]/.test(pos.innerHTML)){
pos.innerHTML = "O";
move += 1;
places.splice(places.indexOf(pos), 1 );
}
if (move > 8){
gameOver();
} else {
user();
}
}
function user(){
table.addEventListener('click', function(event){
let pos = event.target;
let Id = event.target.id;
if (/[1-9]/.test(pos.innerHTML)){
pos.innerHTML = "X";
move += 1;
places.splice(places.indexOf(Id), 1 );
}
if (move > 8){
gameOver();
} else {
computer();
}
});
}
```
<div class="col text-center">
<table class="table text-center">
<tbody id="table">
<tr>
<td id="one">1</td>
<td id="two">2</td>
<td id="three">3</td>
</tr>
<tr>
<td id="four">4</td>
<td id="five">5</td>
<td id="six">6</td>
</tr>
<tr>
<td id="seven">7</td>
<td id="eight">8</td>
<td id="nine">9</td>
</tr>
</tbody>
</table>
<br />
<button class="btn btn-primary" type="button" id="start">Start Game</button>
</div>