forked from appacademy-starters/dom-api-tic-tac-toe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tic-tac-toe.js
54 lines (42 loc) · 1.53 KB
/
tic-tac-toe.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
window.addEventListener("DOMContentLoaded", event => {
//Write a function that tracks the clicks on the page
// Write a code that can track when each tile of the tic tac toe is clicked
let row = []
document.addEventListener('click', (event) => {
console.log(event.target.id.split('-')[1])
})
//When clicked, a mark should be placed/ check for a mark
//Write down all the winning combinations
const winningCondition = [
[0, 1, 2], //Horizational win condition
[3, 4, 5],
[6, 7, 8],
[0, 3, 6], //vertical win condition
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],//Diagonal win condition
[2, 4, 6]
]
//Create a function that checks is the winning conditions have been met
//Display winner
// Function buttons
// If Give up is writted, player loses
// New Game just reloads the page
let a = [1, 2, 3]
let b = [1, 2, 3]
const equal = (row, winningCondition) => {
for(let i = 0; i < winningCondition.length; i++){
if (JSON.stringify(winningCondition[i]) === JSON.stringify(row)) {
let status = document.getElementById("game-status")
status.innerText = "Winner"
}
}
}
console.log(equal(row,winningCondition))
// if (row.length === 3){
// //function check to see if arrays match
// //loops through both arrays
// //if true, print
// // if false, reset row to empty array
// }
})