Spaces:
Running
Running
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Emoji Slot Machine</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
text-align: center; | |
} | |
#slot-machine { | |
display: inline-flex; | |
justify-content: center; | |
align-items: center; | |
border: 3px solid #ccc; | |
padding: 20px; | |
border-radius: 10px; | |
font-size: 2rem; | |
} | |
.slot { | |
padding: 0 10px; | |
} | |
button { | |
font-size: 1rem; | |
padding: 10px 20px; | |
margin-top: 20px; | |
} | |
#balance { | |
font-size: 1.25rem; | |
margin-top: 10px; | |
} | |
#history { | |
font-size: 1rem; | |
margin-top: 10px; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Emoji Slot Machine</h1> | |
<div id="slot-machine"> | |
<div class="slot" id="slot1">π</div> | |
<div class="slot" id="slot2">π</div> | |
<div class="slot" id="slot3">π</div> | |
</div> | |
<button id="spin-btn">Spin</button> | |
<div id="balance">Balance: $<span id="balance-amount">10.00</span></div> | |
<div id="history"></div> | |
<script> | |
document.getElementById('spin-btn').addEventListener('click', function () { | |
var emojis = ['π', 'π', 'π', 'π', 'π']; | |
var slot1 = document.getElementById('slot1'); | |
var slot2 = document.getElementById('slot2'); | |
var slot3 = document.getElementById('slot3'); | |
var balanceAmount = document.getElementById('balance-amount'); | |
var history = document.getElementById('history'); | |
// Deduct 25 cents | |
var newBalance = parseFloat(balanceAmount.textContent) - 0.25; | |
if (newBalance < 0) { | |
alert("Insufficient balance."); | |
return; | |
} | |
balanceAmount.textContent = newBalance.toFixed(2); | |
slot1.textContent = emojis[Math.floor(Math.random() * emojis.length)]; | |
slot2.textContent = emojis[Math.floor(Math.random() * emojis.length)]; | |
slot3.textContent = emojis[Math.floor(Math.random() * emojis.length)]; | |
if (slot1.textContent === slot2.textContent && slot2.textContent === slot3.textContent) { | |
var winAmount = Math.floor(Math.random() * 100) + 1; | |
newBalance = parseFloat(balanceAmount.textContent) + winAmount; | |
balanceAmount.textContent = newBalance.toFixed(2); | |
history.innerHTML += '<p>You won $' + winAmount + '! π</p>'; | |
} | |
}); | |
</script> | |
</body> | |
</html> |