Skip to content
Open

HW #36

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<h4>Test the program</h4>
<div class="formArea">
<label for="words">Enter a word: </label>
<input id="input" type="text" name="words"></input>
</div>
<button id="test" type="submit">Submit</button>
<h4>Output:</h4>
<p id="output"></p>
</head>
<body>
<script src="main.js"></script>
</body>
</html>
33 changes: 33 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -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";
}
};
};
33 changes: 33 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -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 = <HTMLInputElement>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"
}
}
}