<input class="input" id="eval-input" placeholder="2s 3d Td Kc 2d" type="text" />
<button class="input" id="eval-button" type="submit">Evaluate</button>
<div id="result">Score:<br />Hand value:</div>
+ <div id="warning"></div>
<p>Based on Kevin L. Suffecool <a href="http://suffe.cool/poker/evaluator.html">poker hand evaluator</a>.</p>
<footer>Code available on my <a href="https://git.beaudet.xyz/?p=poker-eval.git">git repository</a></footer>
<script src="index.js" type="module" defer></script>
evalButton.addEventListener("click", _ => {
const inputText = document.getElementById("eval-input").value;
const resultDiv = document.getElementById("result");
+ const warningDiv = document.getElementById('warning');
- const result = eval_from_str(inputText);
- const rank = hand_rank(result);
- resultDiv.innerHTML = "Score: " + result + "<br />";
- resultDiv.innerHTML += "Hand value: " + VALUE_STR[rank];
+ try {
+ const cards = parse_cards(inputText);
+ const result = eval_hand(cards);
+ const rank = hand_rank(result);
+ resultDiv.innerHTML = "Score: " + result + "<br />";
+ resultDiv.innerHTML += "Hand value: " + VALUE_STR[rank] + "<br />";
+ warningDiv.style.visibility = 'hidden';
+ warningDiv.innerHTML = "";
+
+ } catch (e) {
+ warningDiv.innerHTML = "😵 Wrong cards provided. Try something like this:<br />2s 3s 4s 5s 6s";
+ warningDiv.style.visibility = 'visible';
+ console.error(e);
+ }
});
const VALUE_STR = [
"Four of a Kind",
"Full House",
"Flush",
- "Staight",
+ "Straight",
"Three of a Kind",
"Two Pair",
"One Pair",