From cd303c14d6ca76dc2bc0c28c0aa6e94bb4a111c4 Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Thu, 10 Feb 2022 20:02:30 +0700 Subject: [PATCH] Validate words on typing the last letter --- src/Game.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Game.tsx b/src/Game.tsx index 89a63b8b7..3ca5a73c6 100644 --- a/src/Game.tsx +++ b/src/Game.tsx @@ -135,6 +135,10 @@ function Game(props: GameProps) { setCurrentGuess((guess) => (guess + key.toLowerCase()).slice(0, wordLength) ); + if ((currentGuess.length + 1) === wordLength && !dictionary.includes(currentGuess + key.toLowerCase())) { + setHint("Not a valid word"); + return; + } tableRef.current?.focus(); setHint(""); } else if (key === "Backspace") {