Initial solution to JavaScript word-count