From 641e476ad6a2fbcbc6e9e0a41e15422b50742a73 Mon Sep 17 00:00:00 2001 From: sigmasternchen Date: Fri, 20 Sep 2024 21:57:35 +0200 Subject: [PATCH] feat: Only accept valid words --- src/components/App.jsx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/components/App.jsx b/src/components/App.jsx index 39d8ce1..8e54ba1 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -61,14 +61,18 @@ export const App = () => { const inputHandler = key => { if (key === "ENTER") { if (currentGuess.length === wordLength) { - setPastGuesses(pastGuesses.concat([currentGuess])); - setCurrentGuess(""); - - if (currentGuess.toUpperCase() === correct.toUpperCase()) { - setGameState(GameState.Won); + if (availableWords.indexOf(currentGuess) === -1) { + setMessage("Not in word list."); } else { - if (pastGuesses.length === numberOfGuesses - 1) { - setGameState(GameState.Lost); + setPastGuesses(pastGuesses.concat([currentGuess])); + setCurrentGuess(""); + + if (currentGuess.toUpperCase() === correct.toUpperCase()) { + setGameState(GameState.Won); + } else { + if (pastGuesses.length === numberOfGuesses - 1) { + setGameState(GameState.Lost); + } } } } else { @@ -94,8 +98,6 @@ export const App = () => { })) ]) - - return