Refactor and add tests

Hello! I was a bit bored, so I wrote some JavaScript. Disclaimer: I have absolutely no idea what I'm doing.

You can [view the first commit without whitespace changes](https://github.com/alexmuller/threewords/commit/b786cf0f8e74ee840e762c2fac904e243a2c1060?w=1) to make it easier to see what's happened.

I've added a test using [Jasmine](https://github.com/pivotal/jasmine) to verify that the code works as expected. You can run the tests by opening `SpecRunner.html` in a browser.