forked from gyrodope69/Tic-tac-toe-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtictac.js
51 lines (49 loc) · 1.28 KB
/
tictac.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
var count = 1;
function fill(control) {
if (count <= 9) {
if (count % 2 != 0) {
document.getElementById(control.id).innerHTML = "X";
} else {
document.getElementById(control.id).innerHTML = "O";
}
count += 1;
checkpattern();
} else {
alert("Match Draw!!!");
reset();
}
}
function reset() {
for (var i = 1; i <= 9; i++) {
document.getElementById("div" + i).innerHTML = "";
}
count = 1;
}
function checkpattern() {
if (
pattern("div1", "div2", "div3") ||
pattern("div1", "div4", "div7") ||
pattern("div7", "div8", "div9") ||
pattern("div3", "div6", "div9") ||
pattern("div4", "div5", "div6") ||
pattern("div2", "div5", "div8") ||
pattern("div1", "div5", "div9") ||
pattern("div3", "div5", "div7")
) {
alert("Winner!!!");
reset();
}
}
function pattern(div1, div2, div3) {
if (
document.getElementById(div1).innerHTML != "" &&
document.getElementById(div2).innerHTML != "" &&
document.getElementById(div3).innerHtml != "" &&
document.getElementById(div1).innerHTML ==
document.getElementById(div2).innerHTML &&
document.getElementById(div2).innerHTML ==
document.getElementById(div3).innerHTML
) {
return true;
}
}