Skip to content

Commit

Permalink
Function to render game board, and event listeners
Browse files Browse the repository at this point in the history
- Only board is visible, but console will log winner, tie, or invalid moves
  • Loading branch information
zalbright90 committed Aug 21, 2024
1 parent a0bc911 commit e3f7a21
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,22 @@ const GameController = (function(Gameboard) {
})(Gameboard);

// Function to render the game board to the DOM
function renderBoard() {
const board = Gameboard.getBoard();
const cells = document.querySelectorAll(".cell");

cells.forEach((cell, index) => {
cell.textContent = board[index];
});
}

// Initial render of the game board
renderBoard();


// Event listeners for player moves
// Event listeners for player moves
document.querySelectorAll('.cell').forEach(cell => {
cell.addEventListener('click', (e) => {
const index = e.target.dataset.index;
GameController.playTurn(index);
});
});

0 comments on commit e3f7a21

Please sign in to comment.