-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathline-counter.js
More file actions
27 lines (25 loc) · 1.3 KB
/
line-counter.js
File metadata and controls
27 lines (25 loc) · 1.3 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
26
27
// Line 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="lineCount">0</span><span class="stat-label">Total Lines</span></div>
<div class="stat-card"><span class="stat-value" id="nonEmptyCount">0</span><span class="stat-label">Non-Empty Lines</span></div>
<div class="stat-card"><span class="stat-value" id="emptyCount">0</span><span class="stat-label">Empty Lines</span></div>
</div>
</div>
`;
function updateCounts() {
const text = document.getElementById('inputText').value;
const lines = text.split('\n');
const nonEmpty = lines.filter(l => l.trim());
document.getElementById('lineCount').textContent = text ? lines.length : 0;
document.getElementById('nonEmptyCount').textContent = nonEmpty.length;
document.getElementById('emptyCount').textContent = lines.length - nonEmpty.length;
}
document.getElementById('inputText').addEventListener('input', updateCounts);
updateCounts();