Simple word counter in javascript