Spaces:
Running
Running
Update index.html
Browse files- index.html +85 -35
index.html
CHANGED
@@ -11,17 +11,22 @@
|
|
11 |
}
|
12 |
|
13 |
#slot-machine {
|
14 |
-
display: inline-
|
15 |
-
justify-content: center;
|
16 |
-
align-items: center;
|
17 |
border: 3px solid #ccc;
|
18 |
padding: 20px;
|
19 |
border-radius: 10px;
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
}
|
22 |
|
23 |
.slot {
|
24 |
padding: 0 10px;
|
|
|
25 |
}
|
26 |
|
27 |
button {
|
@@ -44,42 +49,87 @@
|
|
44 |
<body>
|
45 |
<h1>Emoji Slot Machine</h1>
|
46 |
<div id="slot-machine">
|
47 |
-
<div class="
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
</div>
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
}
|
70 |
-
balanceAmount.textContent = newBalance.toFixed(2);
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
81 |
}
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
</body>
|
85 |
</html>
|
|
|
|
11 |
}
|
12 |
|
13 |
#slot-machine {
|
14 |
+
display: inline-block;
|
|
|
|
|
15 |
border: 3px solid #ccc;
|
16 |
padding: 20px;
|
17 |
border-radius: 10px;
|
18 |
+
}
|
19 |
+
|
20 |
+
.line {
|
21 |
+
display: flex;
|
22 |
+
justify-content: center;
|
23 |
+
align-items: center;
|
24 |
+
margin-bottom: 10px;
|
25 |
}
|
26 |
|
27 |
.slot {
|
28 |
padding: 0 10px;
|
29 |
+
font-size: 2rem;
|
30 |
}
|
31 |
|
32 |
button {
|
|
|
49 |
<body>
|
50 |
<h1>Emoji Slot Machine</h1>
|
51 |
<div id="slot-machine">
|
52 |
+
<div class="line">
|
53 |
+
<div class="slot" id="slot1-1">π</div>
|
54 |
+
<div class="slot" id="slot1-2">π</div>
|
55 |
+
<div class="slot" id="slot1-3">π</div>
|
56 |
+
<div class="slot" id="slot1-4">π</div>
|
57 |
+
<div class="slot" id="slot1-5">π</div>
|
58 |
+
</div>
|
59 |
+
<div class="line">
|
60 |
+
<div class="slot" id="slot2-1">π</div>
|
61 |
+
<div class="slot" id="slot2-2">π</div>
|
62 |
+
<div class="slot" id="slot2-3">π</div>
|
63 |
+
<div class="slot" id="slot2-4">π</div>
|
64 |
+
<div class="slot" id="slot2-5">π</div>
|
65 |
+
</div>
|
66 |
+
<div class="line">
|
67 |
+
<div class="slot" id="slot3-1">π</div>
|
68 |
+
<div class="slot" id="slot3-2">π</div>
|
69 |
+
<div class="slot" id="slot3-3">π</div>
|
70 |
+
<div class="slot" id="slot3-4">π</div>
|
71 |
+
<div class="slot" id="slot3-5">π</div>
|
72 |
+
</div>
|
73 |
+
<div class="line">
|
74 |
+
<div class="slot" id="slot4-1">π</div>
|
75 |
+
<div class="slot" id="slot4-2">π</div>
|
76 |
+
<div class="slot" id="slot4-3">π</div>
|
77 |
+
<div class="slot" id="slot4-4">π</div>
|
78 |
+
<div class="slot" id="slot4-5">π</div>
|
79 |
+
</div>
|
80 |
</div>
|
81 |
+
<button id="spin-btn">Spin</button>
|
82 |
+
<div id="balance">Balance: $<span id="balance-amount">10.00</span></div>
|
83 |
+
<div id="history"></div>
|
84 |
|
85 |
+
<script>
|
86 |
+
function countMatches(line) {
|
87 |
+
const counts = {};
|
88 |
+
for (const emoji of line) {
|
89 |
+
counts[emoji] = (counts[emoji] || 0) + 1;
|
90 |
+
}
|
91 |
+
return Math.max(...Object.values(counts));
|
92 |
+
}
|
93 |
|
94 |
+
document.getElementById('spin-btn').addEventListener('click', function () {
|
95 |
+
var emojis = ['π', 'π', 'π', 'π', 'π'];
|
96 |
+
var balanceAmount = document.getElementById('balance-amount');
|
97 |
+
var history = document.getElementById('history');
|
98 |
+
var winAmount = 0;
|
|
|
|
|
99 |
|
100 |
+
// Deduct 25 cents
|
101 |
+
var newBalance = parseFloat(balanceAmount.textContent) - 0.25;
|
102 |
+
if (newBalance < 0) {
|
103 |
+
alert("Insufficient balance.");
|
104 |
+
return;
|
105 |
+
}
|
106 |
+
balanceAmount.textContent = newBalance.toFixed(2);
|
107 |
|
108 |
+
for (let row = 1; row <= 4; row++) {
|
109 |
+
const line = [];
|
110 |
+
for (let col = 1; col <= 5; col++) {
|
111 |
+
const emoji = emojis[Math.floor(Math.random() * emojis.length)];
|
112 |
+
line.push(emoji);
|
113 |
+
document.getElementById(`slot${row}-${col}`).textContent = emoji;
|
114 |
}
|
115 |
+
|
116 |
+
const matches = countMatches(line);
|
117 |
+
if (matches === 3) {
|
118 |
+
winAmount += 1;
|
119 |
+
} else if (matches === 4) {
|
120 |
+
winAmount += 5;
|
121 |
+
} else if (matches === 5) {
|
122 |
+
winAmount += 100;
|
123 |
+
}
|
124 |
+
}
|
125 |
+
|
126 |
+
if (winAmount > 0) {
|
127 |
+
newBalance = parseFloat(balanceAmount.textContent) + winAmount;
|
128 |
+
balanceAmount.textContent = newBalance.toFixed(2);
|
129 |
+
history.innerHTML += '<p>You won $' + winAmount + '! π</p>';
|
130 |
+
}
|
131 |
+
});
|
132 |
+
</script>
|
133 |
</body>
|
134 |
</html>
|
135 |
+
|