JSFiddle - React, Tailwind, and code Playground

by Sebastian Kay

HTML

<button id="roll">Roll</button>
<br>
<input id="setKeep1">
<input id="setKeep2">
<input id="setKeep3">
<input id="setKeep4">
<input id="setKeep5">
    <br>
<button id="test">Test</button>

CSS

input {
    width : 4em;
}L

JavaScript

// NOTE: jQuery just use for convenience of event handlers

function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min);
}

$("#roll").click(function() {
    $("input").each(function() {
        $(this).val( getRandomInt(1,6) );
    });
    testCurrentRoll();
});

$("#test").click(testCurrentRoll);

function testCurrentRoll() {
    var r = [];
    for (var i = 1; i <= 5; i++)
        r.push(document.getElementById('setKeep' + i).value);
				console.log("Testing Array: " + r);
    		r = r.filter((v,i) => r.indexOf(v) == i)
				
				console.log("Duplicated digets remove: " + r);
    r.sort();
    r = r.join("");
		
    if (/1234|2345|3456/.test(r)) {
        console.log("Small Straight WORKS");
		}else{
				
        console.log("Small Straight NO WORKS");
		}
		
    if (/12345|23456/.test(r)) {
        console.log("Lager Straight WORKS");
		}else{
				
        console.log("Lager Straight NO WORKS");
		}
    
    
}