File tree Expand file tree Collapse file tree 1 file changed +36
-3
lines changed
Expand file tree Collapse file tree 1 file changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ box.forEach((box) => {
2626 }
2727 box . disabled = true
2828 checkwinner ( ) ;
29+ checkdraw ( ) ;
2930
3031 } )
3132
@@ -44,14 +45,45 @@ for(let pattern of winningpattern){
4445 {
4546 if ( pos1 === pos2 && pos2 === pos3 )
4647 {
47- msg . innerText = 'Congratulation You are a Winner'
48- disable ( ) ;
48+ status = 'win'
49+ msgprint ( ) ;
50+ return ;
4951 }
5052 }
5153
5254}
5355 }
5456
57+ checkdraw = function ( ) {
58+ isdraw = true ;
59+ for ( i = 0 ; i < 9 ; i ++ ) {
60+ if ( box [ i ] . innerText === '' ) {
61+
62+
63+ isdraw = false ;
64+ break ;
65+ }
66+ }
67+ if ( isdraw ) {
68+ status = "draw"
69+ msgprint ( ) ;
70+ }
71+
72+ }
73+ msgprint = ( ) => {
74+ if ( status === 'win' )
75+ {
76+ msg . innerText = 'Congratulation You are a Winner'
77+ disable ( ) ;
78+ }
79+ else if ( status === 'draw' ) {
80+ msg . innerText = 'Game is Draw'
81+ disable ( ) ;
82+
83+ }
84+ }
85+
86+
5587 const disable = ( ) => {
5688 for ( let i of box ) {
5789 i . disabled = true ;
@@ -71,7 +103,8 @@ rbutton=document.querySelector(".reset")
71103 resetbutton = ( ) => {
72104 turnX = true ;
73105 enabled ( ) ;
74- msg . innerText = ''
106+ msg . innerText = 'Tic Tac Toe Game'
107+
75108 }
76109
77110msg = document . querySelector ( ".print" )
You can’t perform that action at this time.
0 commit comments