diff --git a/scrabl/index.html b/scrabl/index.html new file mode 100644 index 0000000..613895b --- /dev/null +++ b/scrabl/index.html @@ -0,0 +1,30 @@ + + + + + + + Document + + + + + + + +
+ + + + \ No newline at end of file diff --git a/scrabl/scarbble.js b/scrabl/scarbble.js new file mode 100644 index 0000000..866529b --- /dev/null +++ b/scrabl/scarbble.js @@ -0,0 +1,26 @@ +var tiers = ['aeioulnrst', 'dg', 'bcmp', 'fhvwy', 'k', 'jx', 'qz']; +function scrabscor(name) { + var score = 0; + for (var i = 0; i < name.length; i++) { + if (tiers[0].includes(name[i])) + score += 1; + if (tiers[1].includes(name[i])) + score += 2; + if (tiers[2].includes(name[i])) + score += 3; + if (tiers[3].includes(name[i])) + score += 4; + if (tiers[4].includes(name[i])) + score += 5; + if (tiers[5].includes(name[i])) + score += 8; + if (tiers[6].includes(name[i])) + score += 10; + } + return score; +} +var input = document.querySelector('input'); +var score = document.querySelector('#scrab'); +input.addEventListener('change', function (e) { + score.innerHTML = "Score is: " + scrabscor(input.value); +}); diff --git a/scrabl/scarbble.ts b/scrabl/scarbble.ts new file mode 100644 index 0000000..8140629 --- /dev/null +++ b/scrabl/scarbble.ts @@ -0,0 +1,23 @@ +let tiers : string[] = ['aeioulnrst', 'dg', 'bcmp', 'fhvwy', 'k', 'jx', 'qz'] + +function scrabscor(name : string) { + let score : number = 0; + + for(let i : number = 0; i < name.length; i++) { + if(tiers[0].includes(name[i])) score += 1; + if(tiers[1].includes(name[i])) score += 2; + if(tiers[2].includes(name[i])) score += 3; + if(tiers[3].includes(name[i])) score += 4; + if(tiers[4].includes(name[i])) score += 5; + if(tiers[5].includes(name[i])) score += 8; + if(tiers[6].includes(name[i])) score += 10; + } + + return score; +} + +let input = document.querySelector('input'); +let score = document.querySelector('#scrab'); +input.addEventListener('keyup', (e) => { + score.innerHTML = `Score is: ${scrabscor(input.value)}` +}) \ No newline at end of file