Word Counter Tool
Count words, characters, sentences and reading time.
0
Words
0
Characters
0
Sentences
0
Reading Time
let textBox = document.getElementById("wordText");
textBox.addEventListener("input", countWords);
function countWords(){
let text = textBox.value;
let words = text.trim().match(/\S+/g);
let wordTotal = words ? words.length : 0;
let characters = text.length;
let sentences = text.split(/[.!?]+/) .filter(sentence => sentence.trim().length > 0).length;
let reading = Math.ceil(wordTotal / 200);
document.getElementById("wordCount").innerHTML = wordTotal;
document.getElementById("charCount").innerHTML = characters;
document.getElementById("sentenceCount").innerHTML = sentences;
document.getElementById("readingTime").innerHTML = reading + " min";
}
function clearWords(){
textBox.value="";
countWords();
}
function copyWords(){
textBox.select();
document.execCommand("copy");
alert("Text copied!");
}