diff --git a/nicolator.js b/nicolator.js index d86d79f..74bdbd7 100644 --- a/nicolator.js +++ b/nicolator.js @@ -137,9 +137,10 @@ addEventListener("keyup", event => { }); const check = () => { if (input.value == word) { - clearTimeout(timeout); + clearTimeout(incorrectTimeout); + clearTimeout(timerTimeout); wordDisplay.style.color = "green"; - wordDisplay.innerHTML += " ✅"; + wordDisplay.innerHTML = `${word} ⭕`; setTimeout(() => { wordDisplay.style.color = ""; reset(); @@ -172,17 +173,22 @@ typeTimePerKanaInput.addEventListener("change", (e) => { typeTimePerKana = typeTimePerKanaInput.value; }); const timerFPS = 60; +let incorrectTimeout = null; let timerTimeout = null; -let timeout = null; let word = null; +let wrong = false; const reset = () => { input.value = ""; hint.innerHTML = ""; timer.value = 1; - word = words[Math.round(Math.random() * words.length)]; - timeout = wordDisplay.innerHTML = word; + if (!wrong) { + word = words[Math.round(Math.random() * words.length)]; + } + wordDisplay.innerHTML = word; const typeTime = typeTimePerKana * word.length; - setTimeout(() => { + incorrectTimeout = setTimeout(() => { + wrong = true; + wordDisplay.innerHTML = `${word} ❌`; for (let i = 0; i < word.length; i++) { const letter = word[i]; let key = null; @@ -195,19 +201,19 @@ const reset = () => { } } } - let t = `