From 8ce61ddd47835028fa83eff114dd774f23d2ea7d Mon Sep 17 00:00:00 2001 From: Abdulmajeed Almaymuni Date: Tue, 3 Aug 2021 15:46:08 +0300 Subject: [PATCH] Add solution --- index.html | 17 +++++++++++++++++ solution.js | 20 ++++++++++++++++++++ solution.ts | 22 ++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 index.html create mode 100644 solution.js create mode 100644 solution.ts diff --git a/index.html b/index.html new file mode 100644 index 0000000..2fda444 --- /dev/null +++ b/index.html @@ -0,0 +1,17 @@ + + + + + + + Scrabble + + +

Scrabble

+ + + +

Score is:

+ + + \ No newline at end of file diff --git a/solution.js b/solution.js new file mode 100644 index 0000000..5670740 --- /dev/null +++ b/solution.js @@ -0,0 +1,20 @@ +var letters = { + A: 1, E: 1, I: 1, O: 1, U: 1, L: 1, N: 1, R: 1, S: 1, T: 1, + D: 2, G: 2, + B: 3, C: 3, M: 3, P: 3, + F: 4, H: 4, V: 4, W: 4, Y: 4, + K: 5, + J: 8, X: 8, + Q: 10, Z: 10 +}; +function scrabble(word) { + var score = 0; + for (var i = 0; i < word.length; i++) { + score += letters[word.charAt(i).toUpperCase()]; + } + return score; +} +document.querySelector("#calculate").addEventListener("click", function (event) { + var word = document.querySelector("#text").value; + document.querySelector("#score").textContent = (String(scrabble(word))); +}); diff --git a/solution.ts b/solution.ts new file mode 100644 index 0000000..70c9c81 --- /dev/null +++ b/solution.ts @@ -0,0 +1,22 @@ +const letters = { + A:1, E:1, I:1, O:1, U:1, L:1, N:1, R:1, S:1, T:1, + D:2, G:2, + B:3, C:3, M:3, P:3, + F:4, H:4, V:4, W:4, Y:4, + K:5, + J:8, X:8, + Q:10, Z:10, +} + +function scrabble(word : string): number{ + let score : number = 0; + for(let i = 0; i < word.length; i++){ + score += letters[word.charAt(i).toUpperCase()]; + } + return score; +} + +document.querySelector("#calculate").addEventListener("click", (event) => { + let word = (document.querySelector("#text")).value; + document.querySelector("#score").textContent = (String(scrabble(word))); +}) \ No newline at end of file