File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed
Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -57,10 +57,16 @@ class App extends React.Component {
5757 }
5858
5959 checkWinner = ( values ) => {
60+ if ( values . x . length >= 3 || values . o . length >= 3 ) {
6061 for ( let i = 0 ; i < 9 ; i ++ ) {
6162 for ( let j = 0 ; j < 9 ; j ++ ) {
6263 for ( let k = 0 ; k < 9 ; k ++ ) {
6364 if ( i !== j && i !== k && j !== k ) {
65+ if ( values . x . length + values . o . length === 9 ) {
66+ this . setState ( { winner : 'It\'s a draw!' } )
67+ return ;
68+ }
69+
6470 if ( values . x [ i ] + values . x [ j ] + values . x [ k ] === 15 ) {
6571 this . setState ( { winner : this . state . player1Name } )
6672 return ;
@@ -75,6 +81,7 @@ class App extends React.Component {
7581 }
7682 }
7783 }
84+ }
7885 }
7986
8087
Original file line number Diff line number Diff line change @@ -20,8 +20,10 @@ class Board extends Component {
2020 if ( this . props . winner ) {
2121 if ( this . props . winner === this . props . player1Name ) {
2222 message = < p > < strong > Game over:</ strong > { this . props . player2Name } sucks!</ p > ;
23- } else {
23+ } else if ( this . props . winner === this . props . player2Name ) {
2424 message = < p > < strong > Game over:</ strong > { this . props . player1Name } sucks!</ p > ;
25+ } else {
26+ message = < p > < strong > Game over:</ strong > You both suck!</ p > ;
2527 }
2628 }
2729
You can’t perform that action at this time.
0 commit comments