Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.






                const scrabbleWordValue = word => {
  // scrabble letter values
  const values = { a:1, b:3, c:3, d:2, e:1, f:4, g:2, h:4, i:1, j:8, k:5, l:1, m:3, n:1, o:1, p:3, q:10, r:1, s:1, t:1, u:1, v:4, w:4, x:8, y:4, z:10 };
  // Pre-requesites - check that the string fulfills a good pattern:
  //   - it must start with at least a letter
  //   - followed by have 0 to two asterisks
  //   - repeated at least one time
  //   - optionally at the end it can have a (t) or (d) modifier
  // if it doesn't follow that pattern (invalid or empty), return 0 points
  if(!word.match(/^([a-z][\*]{0,2})+(\([t|d]\))?$/gi)) {
    return 0;
  // word modifier - calculate the multiplier that will be applied to the word:
  //   - 1 (default): the word will not change value
  //   - 2 (if it ends with '(d)'): the word will be multiplied by 2
  //   - 3 (if it ends with '(t)'): the word will be multiplied by 3
  // after calculating the word multiplier, update the word id applicable.
  let wordModifier = 1;
  if (word.indexOf("(") > 0) {
    wordModifier = word.indexOf("(t)") > 0 ? 3 : 2;
    word = word.slice(0,-3);
  // calculate the addition of all letters
  //   - if the letter is an asterisk, use the previous letter
  //   - update the previous letter to current letter
  //   - add the value of the letter to the total
  let previous = 0
  let valueWord = word.split('')
                      .reduce((acc, curr) => {
                        if (curr == '*') curr = previous;
                        previous = curr;
                        return values[curr] + acc;
                      }, 0);

  // if the words has seven letters, add 50 extra points!
  const allLettersBonus = word.replace(/\*/g,'').length == 7 ? 50 : 0;
  // return the value of the word times the multiplier plus the bonus for using all letters
  return valueWord * wordModifier + allLettersBonus;

let word = "he**llo(d)";

console.log(`"${word}" will give you ${scrabbleWordValue(word)} points`);