Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Real time wpm and acc #8

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Removed error
Grivel-l committed Jul 3, 2019
commit 098d3e86c418132ed98c19dbf7ca6157f010da5b
40 changes: 21 additions & 19 deletions main.js
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ getCookie('wordCount') === '' ? setWordCount(50) : setWordCount(getCookie('wordC
getCookie('timeCount') === '' ? setTimeCount(60) : setTimeCount(getCookie('timeCount'));
getCookie('typingMode') === '' ? setTypingMode('wordcount') : setTypingMode(getCookie('typingMode'));
getCookie('punctuation') === '' ? setPunctuation('false') : setPunctuation(getCookie('punctuation'));
setRealTime(getCookie("realTime") !== "" ? getCookie("realTime") : "false");
setRealTime(getCookie("realTime"));

// Find a list of words and display it to textDisplay
function setText() {
@@ -144,25 +144,27 @@ inputField.addEventListener('keydown', e => {
}
}

if (e.key === "Backspace") {
if (inputField.value.length > 0 &&
inputField.value[inputField.value.length - 1] === wordList[currentWord][inputField.value.length - 1]) {
correctKeys -= 1;
}
} else if ((e.key >= "A" && e.key <= "Z") ||
(e.key >= "a" && e.key <= "z")) {
const word = `${inputField.value}${e.key}`;
if (word[word.length - 1] === wordList[currentWord][word.length - 1]) {
correctKeys += 1;
}
} else if (e.key === " ") {
if (inputField.value !== wordList[currentWord]) {
correctKeys -= inputField.value.length;
if (correctKeys < 0) {
correctKeys = 0
if (wordList[currentWord] !== undefined) {
if (e.key === "Backspace") {
if (inputField.value.length > 0 &&
inputField.value[inputField.value.length - 1] === wordList[currentWord][inputField.value.length - 1]) {
correctKeys -= 1;
}
} else if ((e.key >= "A" && e.key <= "Z") ||
(e.key >= "a" && e.key <= "z")) {
const word = `${inputField.value}${e.key}`;
if (word[word.length - 1] === wordList[currentWord][word.length - 1]) {
correctKeys += 1;
}
} else if (e.key === " ") {
if (inputField.value !== wordList[currentWord]) {
correctKeys -= inputField.value.length;
if (correctKeys < 0) {
correctKeys = 0
}
} else {
correctKeys += 1;
}
} else {
correctKeys += 1;
}
}