From b8c0c6ce48e7c1f0a1541efcc0054720580960fe Mon Sep 17 00:00:00 2001 From: Mohammed Rashed Date: Tue, 3 Aug 2021 16:00:17 +0300 Subject: [PATCH] sol DONE --- README.md | 12 ++++++++++++ index.html | 23 +++++++++++++++++++++++ script.js | 27 +++++++++++++++++++++++++++ script.ts | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 index.html create mode 100644 script.js create mode 100644 script.ts diff --git a/README.md b/README.md index cd94655..4e522b5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,15 @@ + +
+ +### Student: Mohammed Rashed Albalawi. + +
+ + + + + + # Week14_Day03_WarmUp-TypeScript ```plain Letter Value diff --git a/index.html b/index.html new file mode 100644 index 0000000..87d73eb --- /dev/null +++ b/index.html @@ -0,0 +1,23 @@ + + + + + + + Scrabble HW + + +

Scrabble Word Score Calculator

+ +
+ + + + +
+ +

The Score is:

+ + + + \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..8061308 --- /dev/null +++ b/script.js @@ -0,0 +1,27 @@ +var word = ''; +var result = 0; +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 getScore(word) { + var score = 0; + for (var i = 0; i < word.length; i++) { + score += letters[word.charAt(i).toUpperCase()]; + } + return score; +} +function calculate(e) { + e.preventDefault(); + word = document.getElementById('word').value; + result = getScore(word); + document.getElementById('result').innerHTML = result.toString(); +} +document.querySelector("button").addEventListener("click", function (e) { + calculate(e); +}); diff --git a/script.ts b/script.ts new file mode 100644 index 0000000..990f688 --- /dev/null +++ b/script.ts @@ -0,0 +1,33 @@ + +let word: string = ''; +let result: number = 0; + +let 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 getScore(word: string) { + let score: number = 0; + for (let i = 0; i < word.length; i++) { + score += letters[word.charAt(i).toUpperCase()]; + } + return score; +} + +function calculate(e) { + e.preventDefault(); + word = (document.getElementById('word')).value; + result = getScore(word); + document.getElementById('result').innerHTML = result.toString(); +} + +document.querySelector("button").addEventListener("click", (e) => { + calculate(e); +}) +