Skip to content

Commit

Permalink
Fix final letter difference bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pcprince committed Jul 25, 2024
1 parent a18171d commit d39a6eb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion guesser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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 = '';
Expand Down

0 comments on commit d39a6eb

Please sign in to comment.