-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.html
51 lines (43 loc) · 1.45 KB
/
index.html
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
51
<!DOCTYPE html>
<html>
<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">I loose</span>
</body>
<script src="dist/pokerhand.min.js"></script>
<script>
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', function() {
let result = -1;
try {
myPokerHand.update($myHand.value);
hisPokerHand.update($hisHand.value);
result = myPokerHand.compareWith(hisPokerHand);
} catch (e) {
$result.innerHTML = e;
}
if (result === 1) {
$result.innerHTML = 'I win';
} else if (result === 2) {
$result.innerHTML = 'I loose';
} else if (result === 3) {
$result.innerHTML = 'Tie';
} else {
$result.innerHTML = 'Error';
}
});
</script>
</html>