Created
October 8, 2012 17:53
-
-
Save davidbauer/3853898 to your computer and use it in GitHub Desktop.
Word counter V2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/