Skip to content

Instantly share code, notes, and snippets.

@davidbauer
Created October 8, 2012 17:53
Show Gist options
  • Save davidbauer/3853898 to your computer and use it in GitHub Desktop.
Save davidbauer/3853898 to your computer and use it in GitHub Desktop.
Word counter V2
function countWords() {
var wordcount = 0;
var text = document.wordcounter.allthosewords.value;
var words = text.match(/\w+\W*/g);
if (words) {
wordcount = words.length;
}
}
function tellCount() {
countWords();
if (wordcount === 0) {
results.innerHTML = "Hey, champion. Can't you count to zero by yourself? How about pasting some real text."
} else if (0 < wordcount && wordcount < 500) {
results.innerHTML = "Your text consists of <i>" + text.length + " characters</i> and <i>" + wordcount + " words</i>. Sorry, not impressed. <br/><br/> <img src='http://media.tumblr.com/tumblr_m8tmyoMNZA1ruser4.jpg'>";
} else {
results.innerHTML = "Your text consists of <i>" + text.length + " characters</i> and <i>" + wordcount + " words</i>. Which is pretty fucking impressive.";
}
}
@davidbauer
Copy link
Author

Danke zum Zweiten. Wird beim nächsten Update berücksichtigt :-) Bis dahin ist eine voll funktionsfähige Version hier zu finden: http://labs.davidbauer.ch/wordcounter/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment