forked from rushi20/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtictac.html
94 lines (91 loc) · 1.64 KB
/
tictac.html
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
<html>
<head>
<style>
.c
{
width:298px;
height:98px;
}
.c1
{
width:97px;
height:96px;
border:1px solid black;
float:left;
}
.clr
{
clear:left;
}
</style>
<script>
var cnt=0;
function f(x)
{
if(cnt%2==0)
{
x.innerHTML="0";
}
else
{
x.innerHTML="x";
}
cnt++;
fr('d1','d2','d3');
fr('d4','d5','d6');
fr('d7','d8','d9');
fr('d1','d4','d7');
fr('d2','d5','d8');
fr('d3','d6','d9');
fr('d1','d5','d9');
fr('d3','d5','d7');
if(cnt==9)
{
alert("draw");
}
}
function fr(m,n,o)
{
var x=document.getElementById(m);
var y=document.getElementById(n);
var z=document.getElementById(o);
if(x.innerHTML=="0" && y.innerHTML=="0" && z.innerHTML=="0")
{
alert("o win");
}
if(x.innerHTML=="x" && y.innerHTML=="x" && z.innerHTML=="x")
{
alert("x win");
}
}
</script>
</head>
<body>
<div style="width:300px;height:300px;">
<div class="c" >
<div class="c1" onclick="f(this)" id="d1" >
</div>
<div class="c1" onclick="f(this)" id="d2" >
</div>
<div class="c1" onclick="f(this)" id="d3">
</div>
</div>
<div class="c">
<div class="c1 clr" onclick="f(this)" id="d4">
</div>
<div class="c1" onclick="f(this)" id="d5">
</div>
<div class="c1" onclick="f(this)" id="d6">
</div>
</div>
<div class="c">
<div class="c1 clr" onclick="f(this)" id="d7">
</div>
<div class="c1" onclick="f(this)" id="d8">
</div>
<div class="c1" onclick="f(this)" id="d9" >
</div>
</div>
</div>
</body>
</html>