From 355cec6300ed4f94c796069fc436debda070506b Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Sun, 13 Mar 2022 19:24:24 +0100 Subject: [PATCH] When no one wins, display a message about the result being a draw --- src/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index a861be0..a22141b 100644 --- a/src/index.js +++ b/src/index.js @@ -2,10 +2,6 @@ import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; -/*TODO - - When no one wins, display a message about the result being a draw. -*/ function Square(props) { const classNames = ['square']; @@ -156,6 +152,11 @@ function calculateWinState(squares) { return {winner: squares[a], line: lines[i]}; } } + + if (squares.every(square => !!square)) { + return {winner: 'Draw :/', line: []}; + } + return null; }