From 63a98f4f8973fe3f7c7245fb61234eaea3e4061c Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 13 Jul 2020 13:01:00 +1000 Subject: [PATCH 1/3] Fix input errors (capital letters, numbers, symbols) Capitals, numbers, symbols, show errors appropriately now. --- main.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index e8f7db5..c2cbe44 100644 --- a/main.js +++ b/main.js @@ -126,7 +126,8 @@ inputField.addEventListener('keydown', e => { if (timerActive) inputFieldClass(); } function inputFieldClass() { - if (e.key >= 'a' && e.key <= 'z' || (e.key === `'` || e.key === ',' || e.key === '.' || e.key === ';')) { + if (isValid(e) == true) { + console.log(e.key); let inputWordSlice = inputField.value + e.key; let currentWordSlice = wordList[currentWord].slice(0, inputWordSlice.length); inputField.className = inputWordSlice === currentWordSlice ? '' : 'wrong'; @@ -456,4 +457,22 @@ function hideThemeCenter() { document.getElementById('command-center').classList.remove('hidden'); } - +// Determines if the input is valid. +function isValid(e) { + if ( + (e.key >= 'a' && e.key <= 'z') || (e.key >= '0' && e.key <= '9') || + (e.key >= '!' && e.key <= '/') || (e.key >= ':' && e.key <= '@') || + (e.key >= '[' && e.key <= '`') || (e.key >= '{' && e.key <= '~') || + e.key == 'A' || e.key == 'B' || e.key == 'C' || e.key == 'D' || + e.key == 'E' || e.key == 'F' || e.key == 'G' || e.key == 'H' || + e.key == 'I' || e.key == 'J' || e.key == 'K' || e.key == 'L' || + e.key == 'M' || e.key == 'N' || e.key == 'O' || e.key == 'P' || + e.key == 'Q' || e.key == 'R' || e.key == 'S' || e.key == 'T' || + e.key == 'U' || e.key == 'V' || e.key == 'W' || e.key == 'X' || + e.key == 'Y' || e.key == 'Z' + ) { + return true; + } else { + return false; + } +} From 24016a49459e5294a04423f4183a0e6c6c9d70dc Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 13 Jul 2020 17:08:19 +1000 Subject: [PATCH 2/3] Update main.js --- main.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/main.js b/main.js index c2cbe44..e377233 100644 --- a/main.js +++ b/main.js @@ -126,7 +126,7 @@ inputField.addEventListener('keydown', e => { if (timerActive) inputFieldClass(); } function inputFieldClass() { - if (isValid(e) == true) { + if (isValid(e.key) == true) { console.log(e.key); let inputWordSlice = inputField.value + e.key; let currentWordSlice = wordList[currentWord].slice(0, inputWordSlice.length); @@ -458,18 +458,18 @@ function hideThemeCenter() { } // Determines if the input is valid. -function isValid(e) { +function isValid(key) { if ( - (e.key >= 'a' && e.key <= 'z') || (e.key >= '0' && e.key <= '9') || - (e.key >= '!' && e.key <= '/') || (e.key >= ':' && e.key <= '@') || - (e.key >= '[' && e.key <= '`') || (e.key >= '{' && e.key <= '~') || - e.key == 'A' || e.key == 'B' || e.key == 'C' || e.key == 'D' || - e.key == 'E' || e.key == 'F' || e.key == 'G' || e.key == 'H' || - e.key == 'I' || e.key == 'J' || e.key == 'K' || e.key == 'L' || - e.key == 'M' || e.key == 'N' || e.key == 'O' || e.key == 'P' || - e.key == 'Q' || e.key == 'R' || e.key == 'S' || e.key == 'T' || - e.key == 'U' || e.key == 'V' || e.key == 'W' || e.key == 'X' || - e.key == 'Y' || e.key == 'Z' + (key >= 'a' && key <= 'z') || (key >= '0' && key <= '9') || + (key >= '!' && key <= '/') || (key >= ':' && key <= '@') || + (key >= '[' && key <= '`') || (key >= '{' && key <= '~') || + key == 'A' || key == 'B' || key == 'C' || key == 'D' || + key == 'E' || key == 'F' || key == 'G' || key == 'H' || + key == 'I' || key == 'J' || key == 'K' || key == 'L' || + key == 'M' || key == 'N' || key == 'O' || key == 'P' || + key == 'Q' || key == 'R' || key == 'S' || key == 'T' || + key == 'U' || key == 'V' || key == 'W' || key == 'X' || + key == 'Y' || key == 'Z' ) { return true; } else { From e5a1fef2fb0bd4a1a90bd6a274ea9aa21feb7f24 Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 13 Jul 2020 18:52:44 +1000 Subject: [PATCH 3/3] Update main.js --- main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/main.js b/main.js index e377233..b4274a3 100644 --- a/main.js +++ b/main.js @@ -127,7 +127,6 @@ inputField.addEventListener('keydown', e => { } function inputFieldClass() { if (isValid(e.key) == true) { - console.log(e.key); let inputWordSlice = inputField.value + e.key; let currentWordSlice = wordList[currentWord].slice(0, inputWordSlice.length); inputField.className = inputWordSlice === currentWordSlice ? '' : 'wrong';