-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (22 loc) · 781 Bytes
/
script.js
File metadata and controls
26 lines (22 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function goBack() {
window.history.back();
}
function updateCounts() {
const text = document.getElementById('textInput').value;
document.getElementById('characterCount').innerText = text.length;
document.getElementById('wordCount').innerText = countWords(text);
document.getElementById('lineCount').innerText = countLines(text);
document.getElementById('sentenceCount').innerText = countSentences(text);
}
function countWords(text) {
if (text.trim().length === 0) return 0;
return text.trim().split(/\s+/).length;
}
function countLines(text) {
if (text.length === 0) return 0;
return text.split(/\n/).length;
}
function countSentences(text) {
if (text.length === 0) return 0;
return text.split(/[.!?]+/).filter(Boolean).length;
}