diff options
Diffstat (limited to 'public/main.js')
-rw-r--r-- | public/main.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/public/main.js b/public/main.js index 13d83e7..01848b3 100644 --- a/public/main.js +++ b/public/main.js @@ -31,6 +31,15 @@ function setRowState(r, s) { }, r); } +function updateKeyboard(keys) { + $$("td[data-key]", e => { + if (keys.hasOwnProperty(e.dataset.key)) { + e.classList.remove("found","present","absent"); + e.classList.add(["absent","present","found"][keys[e.dataset.key]]); + } + }); +} + let done = false; let currentRow = 0; let currentStr = ""; @@ -51,12 +60,21 @@ function processKey(key) { setRow(board[currentRow], currentStr); } +const guessedLetters = {}; async function tryWord() { if (currentStr.length !== 6) return alert("Guesses must use all six letters!"); const r = await fetch("/guess/"+currentStr).then(r => r.json()); if (r.result === false) return alert("Not in word list!"); + for (let i=0;i<6;i++) { + const j = currentStr.charAt(i); + guessedLetters[j] = Math.max(guessedLetters[j]||0, + " -=".indexOf(r.result.charAt(i))); + } + + updateKeyboard(guessedLetters); + setRowState(board[currentRow], r.result); if (r.result === "======") { setTimeout(() => alert("Congratulations!")); |