implements wordCount function needed for question #9