3. Given the following simplified code snippet, what will be the output after calling
game.playTurn() once?
class Player {
constructor(name) { this.name = name; }
}
class Board {
constructor() { this.state = ['-', '-', '-']; }
mark(position, symbol) { this.state[position] = symbol; }
}
class Game {
constructor() {
this.board = new Board();
this.players = [new Player('Alice'), new Player('Bob')];
this.currentPlayerIndex = 0;
}
playTurn() {
const player = this.players[this.currentPlayerIndex];
this.board.mark(0, this.currentPlayerIndex === 0 ? 'X' : 'O');
this.currentPlayerIndex = 1 - this.currentPlayerIndex;
return this.board.state;
}
}
const game = new Game();
console.log(game.playTurn());