create tic tac toe game in react using jsx files
useEffect(()=>{
//checking winner row and col
for (let i = 0; i <= 2; i++){
const idx = (i % 3) * 3 // -> 0,3,6
//check row
if ( (table[idx] + table[idx+1] + table[idx+2] )=== 9 || (table[idx] + table[idx+1] + table[idx+2] ) === 15){
setWinner([idx,idx+1,idx+2])
gameOver()
}
//check col
if ((table[i] + table[i+3] + table[i+6] )=== 9 || (table[i] + table[i+3] + table[i+6] ) === 15){
setWinner([i,i+3,i+6])
gameOver()
}
}
//checking winner diagonal
if ((table[0] + table[4] + table[8] ) === 15 || (table[0] + table[4] + table[8] ) === 9 ){
setWinner([0, 4, 8])
gameOver()
}
if ((table[2] + table[4] + table[6] ) === 9 || (table[2] + table[4] + table[6] ) ===15){
setWinner([2, 4, 6])
gameOver()
}
// check if table completed
if (table.indexOf(0) === -1){
gameOver()
}
}, [table])
Also in JavaScript:
- suspense react
- insert into array js
- javascript length of number
- javascript get the last element of json
- javascript multiplication table
- Scroll to the top of the page using JavaScript?
- nodejs express routing
- json minecraft
- if string have any digits javascript
- javascript get point of line intersection
- react enzyme hooks test
- linkedin api v2 get email address
- how to manage logging using winston for production and development in node js "github"
- how to create dynamic json?
- how to copy to clipboard in p5.js
- add custom marker in react-mapbox-gl
- function expression javascript
- hackerrank fizzbuzz javascript
- debugger js
- web scraping node js puppeteer
- update param in url jquery
- js create object from array
- javascript fibonacci
- javascript detect browser