Skip to content
Permalink
Browse files

When no one wins, display a message about the result being a draw

  • Loading branch information...
Sercan Leylek
Sercan Leylek committed Mar 2, 2019
1 parent 25976e2 commit 3ae966c79df1b17f354eb9e6f1adfff81c18b18a
Showing with 14 additions and 1 deletion.
  1. +14 −1 tic-tac-toe/src/components/Game/Game.js
@@ -100,7 +100,19 @@ class Game extends React.Component {
status = "Winner: " + winner.name;
}
else {
status = 'Next player: ' + (this.state.xIsNext ? 'X' : 'O');
let gameIsDraw = true;
for (let i = 0; i < current.squares.length; i++) {
if (current.squares[i] === null) {
gameIsDraw = false;
break;
}
}
if (gameIsDraw) {
status = "Nobody wins";
}
else {
status = 'Next player: ' + (this.state.xIsNext ? 'X' : 'O');
}
}

let sortButton = "&darr;";
@@ -158,5 +170,6 @@ function calculateWinner(squares) {
return winner;
}
}

return null;
}

0 comments on commit 3ae966c

Please sign in to comment.
You can’t perform that action at this time.