Skip to content

Commit 761dc29

Browse files
committed
fix: fixed a problem with incorrect display of the game result when the value of the count variable is equal to 9 (Mon, Jan 15, 2024, 12:48:52 AM)
1 parent bcbd8c5 commit 761dc29

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

js/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/index.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ function cross(target) {
99
if (count % 2 === 0 && target.textContent === '') {
1010
target.textContent = '◯'
1111
target.classList.add('o')
12-
count++
12+
++count
1313
}
1414
}
1515

1616
function zero(target) {
1717
if (count % 2 !== 0 && target.textContent === '') {
1818
target.textContent = '✕'
1919
target.classList.add('x')
20-
count++
20+
++count
2121
}
2222
}
2323

@@ -43,6 +43,7 @@ function showWin() {
4343

4444
for (let i = 0; i < comboOfWin.length; i++) {
4545
if (squareElements[comboOfWin[i][0]].classList.contains('x') && squareElements[comboOfWin[i][1]].classList.contains('x') && squareElements[comboOfWin[i][2]].classList.contains('x')) {
46+
count = 0;
4647
square.removeEventListener('click', init)
4748
setTimeout(() => {
4849
squareElements[comboOfWin[i][0]].classList.add('main__square-item_win')
@@ -52,18 +53,19 @@ function showWin() {
5253
}, 250)
5354
}
5455
else if (squareElements[comboOfWin[i][0]].classList.contains('o') && squareElements[comboOfWin[i][1]].classList.contains('o') && squareElements[comboOfWin[i][2]].classList.contains('o')) {
56+
count = 0;
5557
square.removeEventListener('click', init)
5658
setTimeout(() => {
5759
squareElements[comboOfWin[i][0]].classList.add('main__square-item_win')
5860
squareElements[comboOfWin[i][1]].classList.add('main__square-item_win')
5961
squareElements[comboOfWin[i][2]].classList.add('main__square-item_win')
6062
res.textContent = '0 WIN'
6163
}, 250)
62-
6364
}
6465
else if (count === 9) {
6566
res.textContent = 'GAME DRAW'
6667
square.removeEventListener('click', init)
68+
6769
}
6870
}
6971
}
@@ -80,3 +82,7 @@ function newGame() {
8082

8183
newGameButton.addEventListener('click', newGame)
8284

85+
86+
setInterval(() => {
87+
console.log(count)
88+
}, 500)

0 commit comments

Comments
 (0)