-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparagraph-counter.js
More file actions
25 lines (23 loc) · 1.19 KB
/
paragraph-counter.js
File metadata and controls
25 lines (23 loc) · 1.19 KB
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
// Paragraph Counter
const toolSection = document.getElementById('toolSection');
toolSection.innerHTML = `
<div class="input-area">
<label for="inputText">Paste or type your text here:</label>
<textarea id="inputText" rows="10" placeholder="Type or paste your text here..."></textarea>
</div>
<div class="output-area">
<div class="stats-grid">
<div class="stat-card"><span class="stat-value" id="paragraphCount">0</span><span class="stat-label">Paragraphs</span></div>
<div class="stat-card"><span class="stat-value" id="avgSentences">0</span><span class="stat-label">Avg Sentences/Paragraph</span></div>
</div>
</div>
`;
function updateCounts() {
const text = document.getElementById('inputText').value;
const paragraphs = text.split(/\n\n+/).filter(p => p.trim());
const sentences = text.split(/[.!?]+/).filter(s => s.trim()).length;
document.getElementById('paragraphCount').textContent = paragraphs.length;
document.getElementById('avgSentences').textContent = paragraphs.length ? Math.round(sentences / paragraphs.length) : 0;
}
document.getElementById('inputText').addEventListener('input', updateCounts);
updateCounts();