-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathindex.html
More file actions
50 lines (42 loc) · 1.56 KB
/
index.html
File metadata and controls
50 lines (42 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Poker Texas Holdem - Cactus Kev's Algorithm</title>
</head>
<body>
<label for="my-hand">My Hand</label>
<input type="text" id="my-hand" name="my-hand" value="KS KH QC QD AD" />
<label for="his-hand">His Hand</label>
<input type="text" id="his-hand" name="his-hand" value="KD KC AS AH TD" />
<button type="button" id="compare" name="compare">Find winner</button>
<span id="result"></span>
<script type="module">
import { PokerHand, CompareResult } from './src/index.ts';
const myPokerHand = new PokerHand('KS KH QC QD AD');
const hisPokerHand = new PokerHand('KD KC AS AH TD');
const $myHand = document.getElementById('my-hand');
const $hisHand = document.getElementById('his-hand');
const $compare = document.getElementById('compare');
const $result = document.getElementById('result');
$compare.addEventListener('click', () => {
let result = -1;
try {
myPokerHand.update($myHand.value);
hisPokerHand.update($hisHand.value);
result = myPokerHand.compareWith(hisPokerHand);
} catch (e) {
$result.innerHTML = e.message;
return;
}
if (result === CompareResult.Win) {
$result.innerHTML = 'I win';
} else if (result === CompareResult.Loss) {
$result.innerHTML = 'I lose';
} else if (result === CompareResult.Tie) {
$result.innerHTML = 'Tie';
}
});
</script>
</body>
</html>