DKL9 GitList
Repositories
DKL9 home
functle
Code
Commits
Branches
Tags
Search
Tree:
c4793cc
Branches
Tags
master
functle
input.js
Improve instructions, export score, split code
dkl9
commited
c4793cc
at 2025-209 17:28:24
input.js
Blame
History
Raw
const keyToToken = { x:"x", 1:"1", 2:"2", q:"^2", c:"^3", s:"sin", e:"exp", l:"ln", "+":"+", "-":"-", "*":"*", "/":"/" }; const maxGuesses = 6; function shakeRow(row) { row.classList.remove("shake"); void row.offsetWidth; row.classList.add("shake"); } const grid = document.getElementById("grid"); for (let i = 0; i < maxGuesses; i++) { const tr = document.createElement("tr"); for (let j = 0; j < tl; j++) { const td = document.createElement("td"); tr.appendChild(td); } grid.appendChild(tr); } let currentRow = 0; let currentInput = []; document.addEventListener("keyup", e => { const row = grid.rows[currentRow]; if (e.key === "Backspace") { if (currentInput.length > 0) { currentInput.pop(); row.cells[currentInput.length].textContent = ""; } else { shakeRow(row); } } else if (e.key === "Enter") { submitGuess(); } else if (keyToToken.hasOwnProperty(e.key)) { if (currentRow >= maxGuesses) { } else if (currentInput.length < tl) { const token = keyToToken[e.key]; currentInput.push(token); const c = row.cells[currentInput.length - 1]; c.style.fontSize = `${3.5 - 0.5 * token.length}em`; c.textContent = token; } else { shakeRow(row); } } });