From 3b324ba56cc9f41c30b2e91738f6d2d5dc9d99f3 Mon Sep 17 00:00:00 2001 From: James Frederix Rolianto <james.frederix@ui.ac.id> Date: Wed, 30 Nov 2022 22:22:44 +0700 Subject: [PATCH] refactor hard mode logic --- src/components/WordInput.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/WordInput.js b/src/components/WordInput.js index 4bc6fb4..60e4b65 100644 --- a/src/components/WordInput.js +++ b/src/components/WordInput.js @@ -133,10 +133,10 @@ const WordInput = () => { var correct = true; for (let i = 0; i < neededWord.length; i++) { - if (!word.includes(neededWord[i])) { + if (word[neededWord[i].index] !== neededWord[i].char) { setPopUp({ show: true, - text: "You need to use the letter that is already correct or misplaced in the word", + text: "You need to use the letter that is already correct in the word", buttonText: "Ok", buttonHandler: () => {}, }); @@ -151,8 +151,8 @@ const WordInput = () => { } if (isEnabled) { - if (e === "correct" || e === "misplaced") { - setNeededWord(prev => [...prev, word[idx]]) + if (e === "correct") { + setNeededWord(prev => [...prev, { char: word[idx], index: idx }]); } } }); -- GitLab