-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
97 lines (83 loc) · 1.78 KB
/
app.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
let currentPlayer = '🐶';
let row0 = ['🐶', '', '😼'];
let row1 = ['🐶', '', '😼'];
let row2 = ['🐶', '', '😼'];
let currentPlayerDisplay = document.querySelector('h1')
let tableDisplay = document.querySelector('table')
function render() {
currentPlayerDisplay.innerHTML = `It's ${currentPlayer}'s turn`;
tableDisplay.innerHTML = `<tr>
<td>${row0[0]}</td>
<td>${row0[1]}</td>
<td>${row0[2]}</td>
</tr>
<tr>
<td>${row1[0]}</td>
<td>${row1[1]}</td>
<td>${row1[2]}</td>
</tr>
<tr>
<td>${row2[0]}</td>
<td>${row2[1]}</td>
<td>${row2[2]}</td>
</tr>`;
}
let checkwinner = () => {
// row 0 horizontal
if (
row0[0] === row0[1] && row0[1] === row0[2]
&& row0[0] !== ''
) {
return row0[0]
}
// row 1 horizontal
if (
row1[0] === row1[1] && row1[1] === row1[2]
&& row1[0] !== ''
) {
return row1[0]
}
// row 2 horizontal
if (
row2[0] === row2[1] && row2[1] === row2[2]
&& row2[0] !== ''
) {
return row2[0]
}
// column 0 vertical
if (
row0[0] === row1[0] && row1[0] === row2[0]
&& row0[0] !== ''
) {
return row0[0]
}
// column 1 vertical
if (
row0[1] === row1[1] && row1[1] === row2[1]
&& row0[1] !== ''
) {
return row0[1]
}
// column 2 vertical
if (
row0[2] === row1[2] && row1[2] === row2[2]
&& row0[2] !== ''
) {
return row0[2]
}
// left to right diagonal
if (
row0[0] === row1[1] && row1[1] === row2[2]
&& row0[0] !== ''
) {
return row0[0]
}
// right to left diagonal
if (
row0[2] === row1[1] && row1[1] === row2[0]
&& row0[2] !== ''
) {
return row0[2]
}
return '';
};