Welcome to the Scrabble challenge!
- Build a simple program using functions, loops, and conditional statements
- Use
git
& GitHub to commit work and open a Pull Request
- Fork this repository and then:
git clone [your repo] && cd js-scrabble-challenge
npm ci # installs dependencies listed in package.json
- Run the tests from your project root directory. There should be a lot of failures to begin with. You can run your test suite in a few ways:
npm test
# or
npx jasmine
# or run jasmine directly
./node_modules/jasmine/bin/jasmine.js
- In GitHub, open a Pull Request from your forked repository to the challenge repository.
- Implement the criteria below locally and push your code to your repository! Every push to a branch that has an open Pull Request will update it automatically with your changes.
- Check the status of the automated tests on the Pull Request - update your implementation if needed.
Given a word, compute the scrabble score for that word.
You'll need these:
Letter | Value |
---|---|
A, E, I, O, U, L, N, R, S, T | 1 |
D, G | 2 |
B, C, M, P | 3 |
F, H, V, W, Y | 4 |
K | 5 |
J, X | 8 |
Q, Z | 10 |
Example "cabbage" should be scored as worth 14 points:
- 3 points for C
- 1 point for A, twice
- 3 points for B, twice
- 2 points for G
- 1 point for E
And to total:
3 + 2x1 + 2x3 + 2 + 1
= 3 + 2 + 6 + 3
= 14
scrabble('') // should return 0
scrabble(" \t\n") // should return 0
scrabble(null) // should return 0
scrabble('a') // should return 1
scrabble('f') // should return 4
scrabble('street') // should return 6
scrabble('quirky') // should return 22
scrabble('OXYPHENBUTAZONE') // should return 41
For some of the extended criteria, you may need to look up functions and techniques you have not used before.
Your solution should support the ability to define specific letters as double and triple score. Letters that count as double are enclosed in a pair of curly brackets {}
- for example, the letter o
would be defined as a double letter in in the word dog like this: d{o}g
. Triple letters are enclosed in a set of square brackets - for example: d[o]g
. Your solution should detect these brackets and apply the correct score modifications. You should add tests for this functionality to the spec file.
Similar to above, your solution should support the ability to define double and triple word scores. To indicate a double word score, the submitted word will be enclose in a pair of curly brackets (for example {dog}
), and for triple word score a pair of square brackets ([dog]
). Your solution should detect these brackets and apply the correct score modifications. You should add tests for this functionality to the spec file.
Split up your scrabble
function in to multiple smaller functions that do one thing only. Read this article on Clean Functions and apply the principles you think are relevant.