From d39a6eb002d3b463e22c44dd6c0ecbbd272064f2 Mon Sep 17 00:00:00 2001 From: Peter Prince Date: Thu, 25 Jul 2024 16:42:52 +0100 Subject: [PATCH] Fix final letter difference bug --- guesser.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/guesser.js b/guesser.js index 1abef69..f774e57 100644 --- a/guesser.js +++ b/guesser.js @@ -117,11 +117,13 @@ function prepareGame () { guessInput.addEventListener('keyup', () => { + const guess = guessInput.value; + let matchIndex = -1; unguessedClips.forEach((clip, index) => { - const isMatch = isCloseMatch(guessInput.value, clip.songName); + const isMatch = isCloseMatch(guess, clip.songName); if (isMatch) { @@ -133,6 +135,16 @@ function prepareGame () { if (matchIndex !== -1) { + // Let user type final letter if that is the only difference + + const likelyClipName = cleanString(unguessedClips[matchIndex].songName); + + if (likelyClipName.substring(0, likelyClipName.length - 1) === guess) { + + return; + + } + console.log('Matched with', matchIndex); guessInput.value = '';