Javascript function to calculate the Scrabble score for a word
This takes any string of characters and totals up how much it would be worth in Scrabble. It ignores any spaces or other non alphabet characters. It doesn't factor in any premium letter or word squares, and it doesn't care if you provide more letters than could possibly fit on a real Scrabble board.
function scrabbleScore(word) {
var scores = [1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10];
var score = 0;
word = word.toUpperCase();
for (var i=0; i<word.length; i++) {
var n = word.charCodeAt(i) - 65;
if (n<0 || n>25) continue;
score += scores[n];
}
return score;
}
function scrabbleScore(word) {
var scores = [1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10];
var score = 0;
word = word.toUpperCase();
for (var i=0; i<word.length; i++) {
var n = word.charCodeAt(i) - 65;
if (n<0 || n>25) continue;
score += scores[n];
}
return score;
}