From 9021aba33872ea6d956b7263f5f867c673a34eea Mon Sep 17 00:00:00 2001 From: your-name Date: Tue, 3 Aug 2021 22:41:39 +0300 Subject: [PATCH] HW --- index.html | 19 +++++++++++++++++++ main.js | 33 +++++++++++++++++++++++++++++++++ main.ts | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 index.html create mode 100644 main.js create mode 100644 main.ts diff --git a/index.html b/index.html new file mode 100644 index 0000000..87b4f03 --- /dev/null +++ b/index.html @@ -0,0 +1,19 @@ + + + + + + +

Test the program

+
+ + +
+ +

Output:

+

+ + + + + \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..cbdb3d2 --- /dev/null +++ b/main.js @@ -0,0 +1,33 @@ +var lib = { + e: 1, a: 1, i: 1, o: 1, n: 1, r: 1, t: 1, l: 1, s: 1, u: 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 +}; +var calcScore = function (text) { + var score = 0; + text = text.toLowerCase(); + for (var _i = 0, text_1 = text; _i < text_1.length; _i++) { + var ch = text_1[_i]; + score += lib[ch]; + } + console.log(score); + return score; +}; +window.onload = function () { + var input = document.getElementById("input"); + var submit = document.getElementById("test"); + var output = document.getElementById("output"); + submit.onclick = function () { + console.log("no"); + if (input.value != "") { + output.innerHTML = calcScore(input.value.trim()).toString(); + } + else { + output.innerHTML = "empty string"; + } + }; +}; diff --git a/main.ts b/main.ts new file mode 100644 index 0000000..2b7cb2b --- /dev/null +++ b/main.ts @@ -0,0 +1,33 @@ +const lib = { + e:1, a:1, i:1, o:1, n:1, r:1, t:1, l:1, s:1, u: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 +} + +const calcScore = (text : any) => { + let score = 0; + text = text.toLowerCase(); + for (let ch of text) { + score += lib[ch]; + } + console.log(score); + return score; +} + +window.onload = function(){ + let input = document.getElementById("input"); + let submit = document.getElementById("test"); + let output = document.getElementById("output"); + submit.onclick = function() { + console.log("no"); + if (input.value != "") { + output.innerHTML = calcScore(input.value.trim()).toString(); + } else { + output.innerHTML = "empty string" + } + } +} \ No newline at end of file