-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
23 lines (19 loc) · 796 Bytes
/
script.js
File metadata and controls
23 lines (19 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
let inputTextArea = document.getElementById("input-textarea");
let characCount = document.getElementById("charac-count");
let wordCount = document.getElementById("word-count");
const wpmCount = document.getElementById("wpm-count");
let startTime;
inputTextArea.addEventListener("input", () => {
characCount.textContent = inputTextArea.value.length;
let txt = inputTextArea.value.trim();
const words = txt.split(/\s+/).filter((item) => item).length;
wordCount.textContent = words;
// Calculate WPM
let currentTime = new Date().getTime();
let timeElapsed = (currentTime - startTime) / 1000;
let wpm = (words / timeElapsed) * 60;
wpmCount.innerText = wpm.toFixed(2);
});
inputTextArea.addEventListener("focus", function() {
startTime = new Date().getTime();
});