JSFiddle - React, Tailwind, and code Playground
HTML
<html lang="DE"><head>
<title> TEST </title>
</head>
<body>
<label for="0"><input type="number" id="0" min="1" max="6" class="card"></label>
<label for="1"><input type="number" id="1" min="1" max="6" class="card"></label>
<label for="2"><input type="number" id="2" min="1" max="6" class="card"></label>
<label for="3"><input type="number" id="3" min="1" max="6" class="card"></label>
<label for="4"><input type="number" id="4" min="1" max="6" class="card"></label>
<p>
<button id="start" onclick="pruefeEintrag()">prüfe FullHouse</button>
</p><div id="ausgabe">.</div>
</body></html>
CSS
body{background: #243269;}
input {
width: 70px;
height: 30px;
margin: 10px;
font-family: Verdana;
font-size: 20px;
font-weight: bold;
text-align: left;
}
#ausgabe{
color: white;
font-family: Verdana;
font-size: 20px;
font-weight: normal;
text-align: left;
}
button{
width: 140px;
height: 40px;
}
JavaScript
const Hands = Object.freeze({
"None": 0,
"FiveOfAKind": 1,
"FullHouse": 2
});
const handsTxt = [];
handsTxt[Hands.None] = ".";
handsTxt[Hands.FiveOfAKind] = "Alle gleich";
handsTxt[Hands.FullHouse] = "FullHouse";
function pruefeEintrag()
{
let txt = "Invalid input";
let values = [];
let inputs = document.querySelectorAll(".card");
for (let i = 0; i < inputs.length; i++) {
let v = inputs[i].value.length ? inputs[i].value * 1 : NaN;
if (Number.isInteger(v)) {
values.push(v);
} else {
break;
}
}
if (values.length == 5) {
txt = handsTxt[getHand(values)];
}
document.getElementById('ausgabe').innerHTML = txt;
}
function getHand(values)
{
values.sort(function(a, b) {
return a - b;
});
let ret = Hands.None;
if (isFiveOfAKind(values)) {
ret = Hands.FiveOfAKind;
} else if (isFullHouse(values)) {
ret = Hands.FullHouse;
}
return ret;
}
function isFiveOfAKind(values)
{
return values[0] == values[1] &&
values[1] == values[2] &&
values[2] == values[3] &&
values[3] == values[4];
}
function isFullHouse(values)
{
let ret = values[0] == values[1] &&
values[1] == values[2] &&
values[3] == values[4];
if (!ret) {
ret |= values[0] == values[1] &&
values[2] == values[3] &&
values[3] == values[4];
}
return ret;
}