From 72f611280771c93428d937ec90f45620dc544e26 Mon Sep 17 00:00:00 2001 From: Miodec Date: Wed, 13 Jan 2021 18:58:18 +0000 Subject: [PATCH] fixed live wpm and raw calculation (avoiding newlines) --- src/js/script.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/js/script.js b/src/js/script.js index 53df64f0a..62fdd1306 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -3147,11 +3147,17 @@ function liveWpmAndRaw() { let chars = 0; let correctWordChars = 0; let spaces = 0; + let newlineoffset = 0; for (let i = 0; i < inputHistory.length; i++) { - if (inputHistory[i] == wordsList[i]) { + let word = wordsList[i + newlineoffset]; + if (word === "\n") { + newlineoffset++; + word = wordsList[i + newlineoffset]; + } + if (inputHistory[i] == word) { //the word is correct //+1 for space - correctWordChars += wordsList[i].length; + correctWordChars += word.length; if (i < inputHistory.length) { spaces++; }