Skip to main content

Simple Tic Tac Toe Game in Javascript

Language


In this project we are going to learn how to create tic-tac-toe game in javascript. This will entertain you and your visitors from your website. Here's the complete javascript code for this game. Have Fun!

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>TIC TAC TOE GAME</title>
  5. </head>
  6. <body>
  7. <script>
  8. if (document.all||document.getElementById){
  9. document.write('<style>.tictac{')
  10. document.write('width:50px;height:50px;')
  11. document.write('}</style>')
  12. }
  13.  
  14. var sqr1
  15. var sqr2
  16. var sqr3
  17. var sqr4
  18. var sqr5
  19. var sqr6
  20. var sqr7
  21. var sqr8
  22. var sqr9
  23. var sqr1T = 0
  24. var sqr2T = 0
  25. var sqr3T = 0
  26. var sqr4T = 0
  27. var sqr5T = 0
  28. var sqr6T = 0
  29. var sqr7T = 0
  30. var sqr8T = 0
  31. var sqr9T = 0
  32. var moveCount = 0
  33. var turn = 0
  34. var mode = 1
  35.  
  36. function vari()
  37. {
  38. sqr1 = document.tic.sqr1.value
  39. sqr2 = document.tic.sqr2.value
  40. sqr3 = document.tic.sqr3.value
  41. sqr4 = document.tic.sqr4.value
  42. sqr5 = document.tic.sqr5.value
  43. sqr6 = document.tic.sqr6.value
  44. sqr7 = document.tic.sqr7.value
  45. sqr8 = document.tic.sqr8.value
  46. sqr9 = document.tic.sqr9.value
  47. }
  48. function check()
  49. {
  50. if(sqr1 == " X " && sqr2 == " X " && sqr3 == " X ")
  51. {
  52. alert("You Win!")
  53. reset()
  54. }
  55. else if(sqr4 == " X " && sqr5 == " X " && sqr6 == " X ")
  56. {
  57. alert("You Win!")
  58. reset()
  59. }
  60. else if(sqr7 == " X " && sqr8 == " X " && sqr9 == " X ")
  61. {
  62. alert("You Win!")
  63. reset()
  64. }
  65. else if(sqr1 == " X " && sqr5 == " X " && sqr9 == " X ")
  66. {
  67. alert("You Win!")
  68. reset()
  69. }
  70. else if(sqr1 == " X " && sqr4 == " X " && sqr7 == " X ")
  71. {
  72. alert("You Win!")
  73. reset()
  74. }
  75. else if(sqr2 == " X " && sqr5 == " X " && sqr8 == " X ")
  76. {
  77. alert("You Win!")
  78. reset()
  79. }
  80. else if(sqr3 == " X " && sqr6 == " X " && sqr9 == " X ")
  81. {
  82. alert("You Win!")
  83. reset()
  84. }
  85. else if(sqr1 == " X " && sqr5 == " X " && sqr9 == " X ")
  86. {
  87. alert("You Win!")
  88. reset()
  89. }
  90. else if(sqr3 == " X " && sqr5 == " X " && sqr7 == " X ")
  91. {
  92. alert("You Win!")
  93. reset()
  94. }
  95. else
  96. {
  97. winCheck()
  98. check2()
  99. drawCheck()
  100. }
  101. }
  102.  
  103. function check2()
  104. {
  105. vari()
  106. drawCheck()
  107. if(sqr1 == " O " && sqr2 == " O " && sqr3 == " O ")
  108. {
  109. alert("You Lose!")
  110. reset()
  111. }
  112. else if(sqr4 == " O " && sqr5 == " O " && sqr6 == " O ")
  113. {
  114. alert("You Lose!")
  115. reset()
  116. }
  117. else if(sqr7 == " O " && sqr8 == " O " && sqr9 == " O ")
  118. {
  119. alert("You Lose!")
  120. reset()
  121. }
  122. else if(sqr1 == " O " && sqr5 == " O " && sqr9 == " O ")
  123. {
  124. alert("You Lose!")
  125. reset()
  126. }
  127. else if(sqr1 == " O " && sqr4 == " O " && sqr7 == " O ")
  128. {
  129. alert("You Lose!")
  130. reset()
  131. }
  132. else if(sqr2 == " O " && sqr5 == " O " && sqr8 == " O ")
  133. {
  134. alert("You Lose!")
  135. reset()
  136. }
  137. else if(sqr3 == " O " && sqr6 == " O " && sqr9 == " O ")
  138. {
  139. alert("You Lose!")
  140. reset()
  141. }
  142. else if(sqr1 == " O " && sqr5 == " O " && sqr9 == " O ")
  143. {
  144. alert("You Lose!")
  145. reset()
  146. }
  147. else if(sqr3 == " O " && sqr5 == " O " && sqr7 == " O ")
  148. {
  149. alert("You Lose!")
  150. reset()
  151. }
  152. }
  153.  
  154. function player1Check()
  155. {
  156. if(sqr1 == " X " && sqr2 == " X " && sqr3 == " X ")
  157. {
  158. alert("Player 1 wins!")
  159. reset()
  160. }
  161. else if(sqr4 == " X " && sqr5 == " X " && sqr6 == " X ")
  162. {
  163. alert("Player 1 wins!")
  164. reset()
  165. }
  166. else if(sqr7 == " X " && sqr8 == " X " && sqr9 == " X ")
  167. {
  168. alert("Player 1 wins!")
  169. reset()
  170. }
  171. else if(sqr1 == " X " && sqr5 == " X " && sqr9 == " X ")
  172. {
  173. alert("Player 1 wins!")
  174. reset()
  175. }
  176. else if(sqr1 == " X " && sqr4 == " X " && sqr7 == " X ")
  177. {
  178. alert("Player 1 wins!")
  179. reset()
  180. }
  181. else if(sqr2 == " X " && sqr5 == " X " && sqr8 == " X ")
  182. {
  183. alert("Player 1 wins!")
  184. reset()
  185. }
  186. else if(sqr3 == " X " && sqr6 == " X " && sqr9 == " X ")
  187. {
  188. alert("Player 1 wins!")
  189. reset()
  190. }
  191. else if(sqr1 == " X " && sqr5 == " X " && sqr9 == " X ")
  192. {
  193. alert("Player 1 wins!")
  194. reset()
  195. }
  196. else if(sqr3 == " X " && sqr5 == " X " && sqr7 == " X ")
  197. {
  198. alert("Player 1 wins!")
  199. reset()
  200. }
  201. else
  202. {
  203. player2Check()
  204. drawCheck()
  205. }
  206. }
  207.  
  208. function player2Check()
  209. {
  210. vari()
  211. drawCheck()
  212. if(sqr1 == " O " && sqr2 == " O " && sqr3 == " O ")
  213. {
  214. alert("Player 2 wins!")
  215. reset()
  216. }
  217. else if(sqr4 == " O " && sqr5 == " O " && sqr6 == " O ")
  218. {
  219. alert("Player 2 wins!")
  220. reset()
  221. }
  222. else if(sqr7 == " O " && sqr8 == " O " && sqr9 == " O ")
  223. {
  224. alert("Player 2 wins!")
  225. reset()
  226. }
  227. else if(sqr1 == " O " && sqr5 == " O " && sqr9 == " O ")
  228. {
  229. alert("Player 2 wins!")
  230. reset()
  231. }
  232. else if(sqr1 == " O " && sqr4 == " O " && sqr7 == " O ")
  233. {
  234. alert("Player 2 wins!")
  235. reset()
  236. }
  237. else if(sqr2 == " O " && sqr5 == " O " && sqr8 == " O ")
  238. {
  239. alert("Player 2 wins!")
  240. reset()
  241. }
  242. else if(sqr3 == " O " && sqr6 == " O " && sqr9 == " O ")
  243. {
  244. alert("Player 2 wins!")
  245. reset()
  246. }
  247. else if(sqr1 == " O " && sqr5 == " O " && sqr9 == " O ")
  248. {
  249. alert("Player 2 wins!")
  250. reset()
  251. }
  252. else if(sqr3 == " O " && sqr5 == " O " && sqr7 == " O ")
  253. {
  254. alert("Player 2 wins!")
  255. reset()
  256. }
  257. }
  258.  
  259. function drawCheck()
  260. {
  261. vari()
  262. moveCount = sqr1T + sqr2T + sqr3T + sqr4T + sqr5T + sqr6T + sqr7T + sqr8T + sqr9T
  263. if(moveCount == 9)
  264. {
  265. reset()
  266. alert("Draw")
  267. }
  268. }
  269.  
  270. function winCheck()
  271. {
  272. check2()
  273. if(sqr1 == " O " && sqr2 == " O " && sqr3T == 0 && turn == 1)
  274. {
  275. document.tic.sqr3.value = " O "
  276. sqr3T = 1;
  277. turn = 0;
  278. }
  279. else if(sqr2 == " O " && sqr3 == " O " && sqr1T == 0 && turn == 1)
  280. {
  281. document.tic.sqr1.value = " O "
  282. sqr1T = 1;
  283. turn = 0;
  284. }
  285. else if(sqr4 == " O " && sqr5 == " O " && sqr6T == 0 && turn == 1)
  286. {
  287. document.tic.sqr6.value = " O "
  288. sqr6T = 1;
  289. turn = 0;
  290. }
  291. else if(sqr5 == " O " && sqr6 == " O " && sqr4T == 0 && turn == 1)
  292. {
  293. document.tic.sqr4.value = " O "
  294. sqr4T = 1;
  295. turn = 0;
  296. }
  297. else if(sqr7 == " O " && sqr8 == " O " && sqr9T == 0 && turn == 1)
  298. {
  299. document.tic.sqr9.value = " O "
  300. sqr9T = 1;
  301. turn = 0;
  302. }
  303. else if(sqr8 == " O " && sqr9 == " O " && sqr7T == 0 && turn == 1)
  304. {
  305. document.tic.sqr7.value = " O "
  306. sqr7T = 1;
  307. turn = 0;
  308. }
  309. else if(sqr1 == " O " && sqr5 == " O " && sqr9T == 0 && turn == 1)
  310. {
  311. document.tic.sqr9.value = " O "
  312. sqr9T = 1;
  313. turn = 0;
  314. }
  315. else if(sqr5 == " O " && sqr9 == " O " && sqr1T == 0 && turn == 1)
  316. {
  317. document.tic.sqr1.value = " O "
  318. sqr1T = 1;
  319. turn = 0;
  320. }
  321. else if(sqr3 == " O " && sqr5 == " O " && sqr7T == 0 && turn == 1)
  322. {
  323. document.tic.sqr7.value = " O "
  324. sqr7T = 1;
  325. turn = 0;
  326. }
  327. else if(sqr7 == " O " && sqr5 == " O " && sqr3T == 0 && turn == 1)
  328. {
  329. document.tic.sqr3.value = " O "
  330. sqr3T = 1;
  331. turn = 0;
  332. }
  333. else if(sqr1 == " O " && sqr3 == " O " && sqr2T == 0 && turn == 1)
  334. {
  335. document.tic.sqr2.value = " O "
  336. sqr2T = 1;
  337. turn = 0;
  338. }
  339. else if(sqr4 == " O " && sqr6 == " O " && sqr5T == 0 && turn == 1)
  340. {
  341. document.tic.sqr5.value = " O "
  342. sqr5T = 1;
  343. turn = 0;
  344. }
  345. else if(sqr7 == " O " && sqr9 == " O " && sqr8T == 0 && turn == 1)
  346. {
  347. document.tic.sqr8.value = " O "
  348. sqr8T = 1;
  349. turn = 0;
  350. }
  351. else if(sqr1 == " O " && sqr7 == " O " && sqr4T == 0 && turn == 1)
  352. {
  353. document.tic.sqr4.value = " O "
  354. sqr4T = 1;
  355. turn = 0;
  356. }
  357. else if(sqr2 == " O " && sqr8 == " O " && sqr5T == 0 && turn == 1)
  358. {
  359. document.tic.sqr5.value = " O "
  360. sqr5T = 1;
  361. turn = 0;
  362. }
  363. else if(sqr3 == " O " && sqr9 == " O " && sqr6T == 0 && turn == 1)
  364. {
  365. document.tic.sqr6.value = " O "
  366. sqr6T = 1;
  367. turn = 0;
  368. }
  369. else if(sqr1 == " O " && sqr5 == " O " && sqr9T == 0 && turn == 1)
  370. {
  371. document.tic.sqr9.value = " O "
  372. sqr9T = 1;
  373. turn = 0;
  374. }
  375. else if(sqr4 == " O " && sqr7 == " O " && sqr1T == 0 && turn == 1)
  376. {
  377. document.tic.sqr1.value = " O "
  378. sqr1T = 1;
  379. turn = 0;
  380. }
  381. else if(sqr5 == " O " && sqr8 == " O " && sqr2T == 0 && turn == 1)
  382. {
  383. document.tic.sqr2.value = " O "
  384. sqr2T = 1;
  385. turn = 0;
  386. }
  387. else if(sqr6 == " O " && sqr9 == " O " && sqr3T == 0 && turn == 1)
  388. {
  389. document.tic.sqr3.value = " O "
  390. sqr3T = 1;
  391. turn = 0;
  392. }
  393. else if(sqr1 == " O " && sqr4 == " O " && sqr7T == 0 && turn == 1)
  394. {
  395. document.tic.sqr7.value = " O "
  396. sqr7T = 1;
  397. turn = 0;
  398. }
  399. else if(sqr2 == " O " && sqr5 == " O " && sqr8T == 0 && turn == 1)
  400. {
  401. document.tic.sqr8.value = " O "
  402. sqr8T = 1;
  403. turn = 0;
  404. }
  405. else if(sqr3 == " O " && sqr6 == " O " && sqr9T == 0 && turn == 1)
  406. {
  407. document.tic.sqr9.value = " O "
  408. sqr9T = 1;
  409. turn = 0;
  410. }
  411. else if(sqr1 == " O " && sqr9 == " O " && sqr5T == 0 && turn == 1)
  412. {
  413. document.tic.sqr5.value = " O "
  414. sqr5T = 1;
  415. turn = 0;
  416. }
  417. else if(sqr3 == " O " && sqr7 == " O " && sqr5T == 0 && turn == 1)
  418. {
  419. document.tic.sqr5.value = " O "
  420. sqr5T = 1;
  421. turn = 0;
  422. }
  423. else
  424. {
  425. computer()
  426. }
  427. check2()
  428. }
  429. function computer()
  430. {
  431. check2()
  432. if(sqr1 == " X " && sqr2 == " X " && sqr3T == 0 && turn == 1)
  433. {
  434. document.tic.sqr3.value = " O "
  435. sqr3T = 1;
  436. turn = 0;
  437. }
  438. else if(sqr2 == " X " && sqr3 == " X " && sqr1T == 0 && turn == 1)
  439. {
  440. document.tic.sqr1.value = " O "
  441. sqr1T = 1;
  442. turn = 0;
  443. }
  444. else if(sqr4 == " X " && sqr5 == " X " && sqr6T == 0 && turn == 1)
  445. {
  446. document.tic.sqr6.value = " O "
  447. sqr6T = 1;
  448. turn = 0;
  449. }
  450. else if(sqr5 == " X " && sqr6 == " X " && sqr4T == 0 && turn == 1)
  451. {
  452. document.tic.sqr4.value = " O "
  453. sqr4T = 1;
  454. turn = 0;
  455. }
  456. else if(sqr7 == " X " && sqr8 == " X " && sqr9T == 0 && turn == 1)
  457. {
  458. document.tic.sqr9.value = " O "
  459. sqr9T = 1;
  460. turn = 0;
  461. }
  462. else if(sqr8 == " X " && sqr9 == " X " && sqr7T == 0 && turn == 1)
  463. {
  464. document.tic.sqr7.value = " O "
  465. sqr7T = 1;
  466. turn = 0;
  467. }
  468. else if(sqr1 == " X " && sqr5 == " X " && sqr9T == 0 && turn == 1)
  469. {
  470. document.tic.sqr9.value = " O "
  471. sqr9T = 1;
  472. turn = 0;
  473. }
  474. else if(sqr5 == " X " && sqr9 == " X " && sqr1T == 0 && turn == 1)
  475. {
  476. document.tic.sqr1.value = " O "
  477. sqr1T = 1;
  478. turn = 0;
  479. }
  480. else if(sqr3 == " X " && sqr5 == " X " && sqr7T == 0 && turn == 1)
  481. {
  482. document.tic.sqr7.value = " O "
  483. sqr7T = 1;
  484. turn = 0;
  485. }
  486. else if(sqr7 == " X " && sqr5 == " X " && sqr3T == 0 && turn == 1)
  487. {
  488. document.tic.sqr3.value = " O "
  489. sqr3T = 1;
  490. turn = 0;
  491. }
  492. else if(sqr1 == " X " && sqr3 == " X " && sqr2T == 0 && turn == 1)
  493. {
  494. document.tic.sqr2.value = " O "
  495. sqr2T = 1;
  496. turn = 0;
  497. }
  498. else if(sqr4 == " X " && sqr6 == " X " && sqr5T == 0 && turn == 1)
  499. {
  500. document.tic.sqr5.value = " O "
  501. sqr5T = 1;
  502. turn = 0;
  503. }
  504. else if(sqr7 == " X " && sqr9 == " X " && sqr8T == 0 && turn == 1)
  505. {
  506. document.tic.sqr8.value = " O "
  507. sqr8T = 1;
  508. turn = 0;
  509. }
  510. else if(sqr1 == " X " && sqr7 == " X " && sqr4T == 0 && turn == 1)
  511. {
  512. document.tic.sqr4.value = " O "
  513. sqr4T = 1;
  514. turn = 0;
  515. }
  516. else if(sqr2 == " X " && sqr8 == " X " && sqr5T == 0 && turn == 1)
  517. {
  518. document.tic.sqr5.value = " O "
  519. sqr5T = 1;
  520. turn = 0;
  521. }
  522. else if(sqr3 == " X " && sqr9 == " X " && sqr6T == 0 && turn == 1)
  523. {
  524. document.tic.sqr6.value = " O "
  525. sqr6T = 1;
  526. turn = 0;
  527. }
  528. else if(sqr1 == " X " && sqr5 == " X " && sqr9T == 0 && turn == 1)
  529. {
  530. document.tic.sqr9.value = " O "
  531. sqr9T = 1;
  532. turn = 0;
  533. }
  534. else if(sqr4 == " X " && sqr7 == " X " && sqr1T == 0 && turn == 1)
  535. {
  536. document.tic.sqr1.value = " O "
  537. sqr1T = 1;
  538. turn = 0;
  539. }
  540. else if(sqr5 == " X " && sqr8 == " X " && sqr2T == 0 && turn == 1)
  541. {
  542. document.tic.sqr2.value = " O "
  543. sqr2T = 1;
  544. turn = 0;
  545. }
  546. else if(sqr6 == " X " && sqr9 == " X " && sqr3T == 0 && turn == 1)
  547. {
  548. document.tic.sqr3.value = " O "
  549. sqr3T = 1;
  550. turn = 0;
  551. }
  552. else if(sqr1 == " X " && sqr4 == " X " && sqr7T == 0 && turn == 1)
  553. {
  554. document.tic.sqr7.value = " O "
  555. sqr7T = 1;
  556. turn = 0;
  557. }
  558. else if(sqr2 == " X " && sqr5 == " X " && sqr8T == 0 && turn == 1)
  559. {
  560. document.tic.sqr8.value = " O "
  561. sqr8T = 1;
  562. turn = 0;
  563. }
  564. else if(sqr3 == " X " && sqr6 == " X " && sqr9T == 0 && turn == 1)
  565. {
  566. document.tic.sqr9.value = " O "
  567. sqr9T = 1;
  568. turn = 0;
  569. }
  570. else if(sqr1 == " X " && sqr9 == " X " && sqr5T == 0 && turn == 1)
  571. {
  572. document.tic.sqr5.value = " O "
  573. sqr5T = 1;
  574. turn = 0;
  575. }
  576. else if(sqr3 == " X " && sqr7 == " X " && sqr5T == 0 && turn == 1)
  577. {
  578. document.tic.sqr5.value = " O "
  579. sqr5T = 1;
  580. turn = 0;
  581. }
  582. else
  583. {
  584. AI()
  585. }
  586. check2()
  587. }
  588.  
  589. function AI()
  590. {
  591. vari()
  592. if(document.tic.sqr5.value == " " && turn == 1)
  593. {
  594. document.tic.sqr5.value = " O "
  595. turn = 0
  596. sqr5T = 1
  597. }
  598. else if(document.tic.sqr1.value == " " && turn == 1)
  599. {
  600. document.tic.sqr1.value = " O "
  601. turn = 0
  602. sqr1T = 1
  603. }
  604. else if(document.tic.sqr9.value == " " && turn == 1)
  605. {
  606. document.tic.sqr9.value = " O "
  607. turn = 0
  608. sqr9T = 1
  609. }
  610. else if(document.tic.sqr6.value == " " && turn == 1)
  611. {
  612. document.tic.sqr6.value = " O "
  613. turn = 0
  614. sqr6T = 1
  615. }
  616. else if(document.tic.sqr2.value == " " && turn == 1)
  617. {
  618. document.tic.sqr2.value = " O "
  619. turn = 0
  620. sqr2T = 1
  621. }
  622. else if(document.tic.sqr8.value == " " && turn == 1)
  623. {
  624. document.tic.sqr8.value = " O "
  625. turn = 0
  626. sqr8T = 1
  627. }
  628. else if(document.tic.sqr3.value == " " && turn == 1)
  629. {
  630. document.tic.sqr3.value = " O "
  631. turn = 0
  632. sqr3T = 1
  633. }
  634. else if(document.tic.sqr7.value == " " && turn == 1)
  635. {
  636. document.tic.sqr7.value = " O "
  637. turn = 0
  638. sqr7T = 1
  639. }
  640. else if(document.tic.sqr4.value == " " && turn == 1)
  641. {
  642. document.tic.sqr4.value = " O "
  643. turn = 0
  644. sqr4T = 1
  645. }
  646. check2()
  647. }
  648.  
  649. function reset()
  650. {
  651. document.tic.sqr1.value = " "
  652. document.tic.sqr2.value = " "
  653. document.tic.sqr3.value = " "
  654. document.tic.sqr4.value = " "
  655. document.tic.sqr5.value = " "
  656. document.tic.sqr6.value = " "
  657. document.tic.sqr7.value = " "
  658. document.tic.sqr8.value = " "
  659. document.tic.sqr9.value = " "
  660. sqr1T = 0
  661. sqr2T = 0
  662. sqr3T = 0
  663. sqr4T = 0
  664. sqr5T = 0
  665. sqr6T = 0
  666. sqr7T = 0
  667. sqr8T = 0
  668. sqr9T = 0
  669. vari()
  670. turn = 0
  671. moveCount = 0
  672. }
  673.  
  674. function resetter()
  675. {
  676. reset()
  677. }
  678. </script>
  679.  
  680. <center>
  681. <h2 style="margin-top:200px;">TIC TAC TOE GAME</h2>
  682. <form NAME="tic" method="post">
  683. <input type="button" style="width:100px; height:100px; padding:40px; font-size:20px;" name="sqr1" class="tictac" value=" " onClick="if(document.tic.sqr1.value == ' ' && turn == 0 && mode == 1) {document.tic.sqr1.value = ' X '; sqr1T = 1; turn = 1; vari(); check();} else if(document.tic.sqr1.value == ' ' && turn == 1 && mode == 2) {document.tic.sqr1.value = ' X '; sqr1T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr1.value == ' ' && turn == 0 && mode == 2) {document.tic.sqr1.value = ' O '; sqr1T = 1; turn = 1; vari(); player1Check()} drawCheck()">
  684. <input type="button" style="width:100px; height:100px; padding:40px; font-size:20px;" name="sqr2" class="tictac" value=" " onClick="if(document.tic.sqr2.value == ' ' && turn == 0 && mode == 1) {document.tic.sqr2.value = ' X '; sqr2T = 1; turn = 1; vari(); check();} else if(document.tic.sqr2.value == ' ' && turn == 1 && mode == 2) {document.tic.sqr2.value = ' X '; sqr2T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr2.value == ' ' && turn == 0 && mode == 2) {document.tic.sqr2.value = ' O '; sqr2T = 1; turn = 1; vari(); player1Check()} drawCheck()">
  685. <input type="button" style="width:100px; height:100px; padding:40px; font-size:20px;" name="sqr3" class="tictac" value=" " onClick="if(document.tic.sqr3.value == ' ' && turn == 0 && mode == 1) {document.tic.sqr3.value = ' X '; sqr3T = 1; turn = 1; vari(); check();} else if(document.tic.sqr3.value == ' ' && turn == 1 && mode == 2) {document.tic.sqr3.value = ' X '; sqr3T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr3.value == ' ' && turn == 0 && mode == 2) {document.tic.sqr3.value = ' O '; sqr3T = 1; turn = 1; vari(); player1Check()} drawCheck()"><br />
  686. <input type="button" style="width:100px; height:100px; padding:40px; font-size:20px;" name="sqr4" class="tictac" value=" " onClick="if(document.tic.sqr4.value == ' ' && turn == 0 && mode == 1) {document.tic.sqr4.value = ' X '; sqr4T = 1; turn = 1; vari(); check();} else if(document.tic.sqr4.value == ' ' && turn == 1 && mode == 2) {document.tic.sqr4.value = ' X '; sqr4T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr4.value == ' ' && turn == 0 && mode == 2) {document.tic.sqr4.value = ' O '; sqr4T = 1; turn = 1; vari(); player1Check()} drawCheck()">
  687. <input type="button" style="width:100px; height:100px; padding:40px; font-size:20px;" name="sqr5" class="tictac" value=" " onClick="if(document.tic.sqr5.value == ' ' && turn == 0 && mode == 1) {document.tic.sqr5.value = ' X '; sqr5T = 1; turn = 1; vari(); check();} else if(document.tic.sqr5.value == ' ' && turn == 1 && mode == 2) {document.tic.sqr5.value = ' X '; sqr5T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr5.value == ' ' && turn == 0 && mode == 2) {document.tic.sqr5.value = ' O '; sqr5T = 1; turn = 1; vari(); player1Check()} drawCheck()">
  688. <input type="button" style="width:100px; height:100px; padding:40px; font-size:20px;" name="sqr6" class="tictac" value=" " onClick="if(document.tic.sqr6.value == ' ' && turn == 0 && mode == 1) {document.tic.sqr6.value = ' X '; sqr6T = 1; turn = 1; vari(); check();} else if(document.tic.sqr6.value == ' ' && turn == 1 && mode == 2) {document.tic.sqr6.value = ' X '; sqr6T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr6.value == ' ' && turn == 0 && mode == 2) {document.tic.sqr6.value = ' O '; sqr6T = 1; turn = 1; vari(); player1Check()} drawCheck()"><br />
  689. <input type="button" style="width:100px; height:100px; padding:40px; font-size:20px;" name="sqr7" class="tictac" value=" " onClick="if(document.tic.sqr7.value == ' ' && turn == 0 && mode == 1) {document.tic.sqr7.value = ' X '; sqr7T = 1; turn = 1; vari(); check();} else if(document.tic.sqr7.value == ' ' && turn == 1 && mode == 2) {document.tic.sqr7.value = ' X '; sqr7T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr7.value == ' ' && turn == 0 && mode == 2) {document.tic.sqr7.value = ' O '; sqr7T = 1; turn = 1; vari(); player1Check()} drawCheck()">
  690. <input type="button" style="width:100px; height:100px; padding:40px; font-size:20px;" name="sqr8" class="tictac" value=" " onClick="if(document.tic.sqr8.value == ' ' && turn == 0 && mode == 1) {document.tic.sqr8.value = ' X '; sqr8T = 1; turn = 1; vari(); check();} else if(document.tic.sqr8.value == ' ' && turn == 1 && mode == 2) {document.tic.sqr8.value = ' X '; sqr8T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr8.value == ' ' && turn == 0 && mode == 2) {document.tic.sqr8.value = ' O '; sqr8T = 1; turn = 1; vari(); player1Check()} drawCheck()">
  691. <input type="button" style="width:100px; height:100px; padding:40px; font-size:20px;" name="sqr9" class="tictac" value=" " onClick="if(document.tic.sqr9.value == ' ' && turn == 0 && mode == 1) {document.tic.sqr9.value = ' X '; sqr9T = 1; turn = 1; vari(); check();} else if(document.tic.sqr9.value == ' ' && turn == 1 && mode == 2) {document.tic.sqr9.value = ' X '; sqr9T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr9.value == ' ' && turn == 0 && mode == 2) {document.tic.sqr9.value = ' O '; sqr9T = 1; turn = 1; vari(); player1Check()} drawCheck()">
  692. </form>
  693. </center>
  694. </body>
  695. </html>

Hope this will help you.

 

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

Submitted byRonewa Bangira (not verified)on Tue, 09/11/2018 - 19:28

Thanks a lot for the codes, they really helped the most in completing my assignment. Is it possible though for you to make this page again with 2 human players instead?

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.