Skip to content
Open
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@

<hr />

### <b> Student:</b> Mohammed Rashed Albalawi.

<hr />






# Week14_Day03_WarmUp-TypeScript
```plain
Letter Value
Expand Down
23 changes: 23 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!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">
<title>Scrabble HW</title>
</head>
<body>
<h1>Scrabble Word Score Calculator</h1>

<form>
<label for="word">Word: </label>
<input type="text" id="word" />

<button onclick="calculate">Calculate!</button>
</form>

<h4>The Score is: <span id="result"></span> </h4>

<script src="./script.js"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -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);
});
33 changes: 33 additions & 0 deletions script.ts
Original file line number Diff line number Diff line change
@@ -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 = (<HTMLInputElement>document.getElementById('word')).value;
result = getScore(word);
document.getElementById('result').innerHTML = result.toString();
}

document.querySelector("button").addEventListener("click", (e) => {
calculate(e);
})