JSFiddle - React, Tailwind, and code Playground
by frogggeee McFrogggeee
HTML
<!DOCTYPE html>
<html>
<head>
<body>
<h1>rainbow slot machine</h1>
<p>by frogggeee</p>
<p>click to spin. that's all.</p>
<canvas id = "theCanvas" width = "540" height = "360"></canvas>
<script>
document.addEventListener("mousedown", onDown, false);
let spinning = false;
let odds = 8;
let slot1 = 1;
let slot2 = 3;
let slot3 = 1;
let combos = [111, 222, 333, 444, 555, 666];
let combo = 0;
function onDown() {
spin();
}
function spin() {
let win = (Math.floor(Math.random()) * odds);
if (odds == 1) {
combo = combos[(Math.floor(Math.random()) * 6)];
} else {
combo = (Math.floor(Math.random()) * 6) + (Math.floor(Math.random()) * 6) + (Math.floor(Math.random()) * 6);
}
slot1 = combo.charAt(1);
slot2 = combo.charAt(2);
slot3 = combo.charAt(3);
alert (slot1 + "" + slot2 + "" + slot3);
}
</script>
</body>
</head>
</html>