forked from TinkerHubKMCTCE/Fi-Pro-Challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtb.js
26 lines (26 loc) · 776 Bytes
/
tb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
document.addEventListener('DOMContentLoaded',() =>
{
const squares=document.querySelectorAll('.grid div')
const playerDisplay=document.querySelector('#player')
let currentPlayer='playerX'
squares.forEach(square =>
{
square.addEventListener('click',clickOutcome)
})
function clickOutcome(e)
{
const squareArray=Array.from(squares)
const index=squareArray.indexOf(e.target)
playerDisplay.innerHTML=currentPlayer
if(currentPlayer==='playerX')
{
squares[index].classList.add('playerX')
currentPlayer='player0'
}
else
{
squares[index].classList.add('player0')
currentPlayer='playerX'
}
}
})