Avatar of ndl101

ndl101's solution

to Scrabble Score in the TypeScript Track

Published at May 28 2020 · 0 comments
Test suite

Given a word, compute the scrabble score for that word.

Letter Values

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


"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 + 2*1 + 2*3 + 2 + 1
  • = 3 + 2 + 6 + 3
  • = 5 + 9
  • = 14


  • You can play a double or a triple letter.
  • You can play a double or a triple word.


Go through the setup instructions for TypeScript to install the necessary dependencies:



Install assignment dependencies:

$ yarn install

Making the test suite pass

Execute the tests with:

$ yarn test

In the test suites all tests but the first have been skipped.

Once you get a test passing, you can enable the next one by changing xit to it.


Inspired by the Extreme Startup game https://github.com/rchatley/extreme_startup

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


import score from './scrabble-score'

describe('Scrabble', () => {
  it('scores an empty word as zero', () => expect(score('')).toEqual(0))

  xit('scores a null as zero', () => expect(score(undefined)).toEqual(0))

  xit('scores a very short word', () => expect(score('a')).toEqual(1))

  xit('scores the word by the number of letters', () => expect(score('street')).toEqual(6))

  xit('scores more complicated words with more', () => expect(score('quirky')).toEqual(22))

  xit('scores case insensitive words', () => expect(score('OXYPHENBUTAZONE')).toEqual(41))

function score(word?: string): number {
    return word ? word.toLocaleUpperCase().split('').reduce((acc: number, curr: string) => {
        return acc + getPoint(curr)
    }, 0) : 0

function getPoint(letter: string): number {
    switch(letter) {
        case "A":
        case "E":
        case "I":
        case "O":
        case "U":
        case "L":
        case "N":
        case "R":
        case "S":
        case "T":
            return 1;
        case "D":
        case "G":
            return 2;
        case "B":
        case "C":
        case "M":
        case "P":
            return 3;
        case "F":
        case "H":
        case "V":
        case "W":
        case "Y":
            return 4;
        case "K":
            return 5;
        case "J":
        case "X":
            return 8;
        case "Q":
        case "Z":
            return 10;
            throw new Error();

export default score;

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?