Changed around line 1
+ const colors = ['#ff6f61', '#ffcc5c', '#88d8b0', '#96ceb4', '#ffeead'];
+ const boardSize = 8;
+ let score = 0;
+ let board = [];
+
+ function createBoard() {
+ const gameBoard = document.getElementById('game-board');
+ gameBoard.innerHTML = '';
+ board = [];
+
+ for (let row = 0; row < boardSize; row++) {
+ board[row] = [];
+ for (let col = 0; col < boardSize; col++) {
+ const cell = document.createElement('div');
+ cell.classList.add('cell');
+ cell.dataset.row = row;
+ cell.dataset.col = col;
+ cell.style.backgroundColor = getRandomColor();
+ cell.addEventListener('click', handleCellClick);
+ gameBoard.appendChild(cell);
+ board[row][col] = cell;
+ }
+ }
+ }
+
+ function getRandomColor() {
+ return colors[Math.floor(Math.random() * colors.length)];
+ }
+
+ function handleCellClick(event) {
+ const clickedCell = event.target;
+ const row = parseInt(clickedCell.dataset.row);
+ const col = parseInt(clickedCell.dataset.col);
+
+ const adjacentCells = [
+ { row: row - 1, col },
+ { row: row + 1, col },
+ { row, col: col - 1 },
+ { row, col: col + 1 }
+ ];
+
+ adjacentCells.forEach(adjacent => {
+ const adjRow = adjacent.row;
+ const adjCol = adjacent.col;
+ if (adjRow >= 0 && adjRow < boardSize && adjCol >= 0 && adjCol < boardSize) {
+ if (board[adjRow][adjCol].style.backgroundColor === clickedCell.style.backgroundColor) {
+ score += 10;
+ document.getElementById('score').textContent = score;
+ board[adjRow][adjCol].style.backgroundColor = getRandomColor();
+ clickedCell.style.backgroundColor = getRandomColor();
+ }
+ }
+ });
+ }
+
+ window.onload = createBoard;