Code Link : https://github.com/henil11d/TicTacToi
Output : https://henil11d.github.io/TicTacToi/
You Check My Javascript Code On github page Solve My Problem
Problem is -:When Start Game Show Winner Name First Time after Program Run Completely i am already Provided my code and output link please help.
You can update my code in GitHub page and help me
Please Help.
Advertisement
Answer
JavaScript
x
47
47
1
var c = 1;
2
function fil(elem) {
3
if (c <= 9) {
4
if (c % 2 != 0) {
5
document.getElementById(elem.id).innerHTML = "X";
6
d = 0;
7
}
8
else {
9
document.getElementById(elem.id).innerHTML = "O";
10
d = 1;
11
}
12
c++;
13
if (CkeckWin()) {
14
if (d == 0) {
15
alert("win X");
16
}else{
17
alert("win O");
18
}
19
reset();
20
}
21
} else {
22
alert("Match is Draw");
23
reset();
24
}
25
}
26
function reset() {
27
for (var i = 1; i <= 9; i++) {
28
document.getElementById("d" + i).innerHTML = "";
29
}
30
c = 1;
31
}
32
33
function CkeckWin() {
34
if (didvalue('d1', 'd2', 'd3') || didvalue('d1', 'd5', 'd9') || didvalue('d7', 'd8', 'd9') || didvalue('d1', 'd4', 'd7') ||
35
didvalue('d3', 'd6', 'd9') || didvalue('d3', 'd5', 'd7') || didvalue('d4', 'd5', 'd6') || didvalue('d2', 'd5', 'd8')) {
36
return true;
37
}
38
}
39
function didvalue(id1, id2, id3) {
40
if (getData(id1) != "" && getData(id2) != "" && getData(id3) != "" &&
41
getData(id1) == getData(id2) && getData(id2) == getData(id3)) {
42
return true;
43
}
44
}
45
function getData(Did) {
46
return document.getElementById(Did).innerHTML.trim();
47
}
JavaScript
1
77
77
1
*{
2
margin: 0;
3
padding: 0;
4
}
5
body{
6
background-color: rgb(44, 43, 43);
7
text-align: center;
8
user-select: none;
9
}
10
h1{
11
color: aqua;
12
font-size: 100px;
13
font-family: 'Courier New', Courier, monospace;
14
text-shadow: 0 0 6px rgb(234, 236, 122);
15
margin-top: 60px;
16
}
17
a{
18
font-family: sans-serif;
19
padding: 15px;
20
margin-right: 40px;
21
color: rgb(252, 252, 252);
22
background-color: rgb(84, 24, 224);
23
border-radius: 25px;
24
font-size: 28px;
25
box-shadow: 0 0 15px 0 rgb(19, 18, 18);
26
border-bottom-left-radius: 5px;
27
border-top-right-radius: 5px ;
28
text-decoration: none;
29
font-weight: bold;
30
}
31
a:hover{
32
color: black;
33
background-color: rgb(1, 198, 247);
34
border-radius: 28px;
35
box-shadow: 0 0 10px 0 rgb(13, 3, 160);
36
border-top-left-radius: 5px;
37
border-bottom-right-radius: 5px ;
38
}
39
a:active{
40
color: red;
41
}
42
.box{
43
border: 3px solid rgb(101, 250, 87);
44
height: 170px;
45
font-size: 140px;
46
width: 170px;
47
cursor: pointer;
48
color: rgb(3, 176, 182);
49
float: left;
50
}
51
.box:hover{
52
background-color: rgb(106, 109, 109);
53
}
54
.box:active{
55
background-color: antiquewhite;
56
}
57
.main{
58
position: relative;
59
top: 60px;
60
left: 140px;
61
width: 800px;
62
margin: auto;
63
/* display: none; */
64
}
65
#d1,#d4,#d7{
66
clear: left;
67
border-left: none;
68
}
69
#d1,#d2,#d3{
70
border-top: none;
71
}
72
#d3,#d6,#d9{
73
border-right: none;
74
}
75
#d7,#d8,#d9{
76
border-bottom: none;
77
}
JavaScript
1
26
26
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
<title> Henil Code </title>
5
<link rel="stylesheet" href="Tecto.css">
6
<script src="https://code.jquery.com/jquery-3.6.0.min.js"> </script>
7
<script src="te.js"> </script>
8
</head>
9
<body>
10
<!-- <a href="https://henilcodes.github.io/PH/"> Henil Code </a> -->
11
<h1> tic tac toe </h1>
12
<div class="main">
13
<div id="d1" class="box" onclick="fil(this)"> </div>
14
<div id="d2" class="box" onclick="fil(this)"> </div>
15
<div id="d3" class="box" onclick="fil(this)"> </div>
16
<div id="d4" class="box" onclick="fil(this)"> </div>
17
<div id="d5" class="box" onclick="fil(this)"> </div>
18
<div id="d6" class="box" onclick="fil(this)"> </div>
19
<div id="d7" class="box" onclick="fil(this)"> </div>
20
<div id="d8" class="box" onclick="fil(this)"> </div>
21
<div id="d9" class="box" onclick="fil(this)"> </div>
22
</div>
23
24
</body>
25
26
</html>
trim()
function return like" "
to""
you need to add trim()
Change Code
JavaScript
1
4
1
function getData(Did) {
2
return document.getElementById(Did).innerHTML.trim();// trim() data
3
}
4