Character Counter
Characters: 0
Words: 0
Sentences: 0
Paragraphs: 0
function countText() {
const text = document.getElementById(‘textInput’).value;// Character Count
const charCount = text.length;// Word Count
const wordCount = text.trim().split(/s+/).filter(word => word.length > 0).length;// Sentence Count (counts periods, exclamation marks, or question marks as sentence delimiters)
const sentenceCount = text.split(/[.!?]+/).filter(sentence => sentence.trim().length > 0).length;// Paragraph Count (counts line breaks as paragraph delimiters)
const paragraphCount = text.split(/n+/).filter(paragraph => paragraph.trim().length > 0).length;// Display the counts
document.getElementById(‘charCount’).innerText = charCount;
document.getElementById(‘wordCount’).innerText = wordCount;
document.getElementById(‘sentenceCount’).innerText = sentenceCount;
document.getElementById(‘paragraphCount’).innerText = paragraphCount;
}
Visited 78 times, 1 visit(s) today