<!DOCTYPE html>
<html>
<head>
<style>
.slot-machine {
background: #2c3e50;
padding: 20px;
border-radius: 10px;
text-align: center;
}
.reels {
display: flex;
justify-content: center;
gap: 10px;
margin: 20px;
}
.reel {
width: 100px;
height: 100px;
background: #ecf0f1;
border: 3px solid #bdc3c7;
border-radius: 5px;
font-size: 50px;
line-height: 100px;
transition: transform 0.1s;
}
#spin-btn {
padding: 10px 30px;
font-size: 18px;
background: #27ae60;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
#result {
margin-top: 20px;
font-size: 24px;
color: white;
}
</style>
</head>
<body>
<div class="slot-machine">
<div class="reels">
<div class="reel" id="reel1">🍒</div>
<div class="reel" id="reel2">🍒</div>
<div class="reel" id="reel3">🍒</div>
</div>
<button id="spin-btn">Spin!</button>
<div id="result"></div>
</div>
<script>
const symbols = ['🍒', '🍊', '🍋', '🍇', '🔔', '💎'];
const reels = document.querySelectorAll('.reel');
const spinBtn = document.getElementById('spin-btn');
const result = document.getElementById('result');
let isSpinning = false;
function getRandomSymbol() {
return symbols
[Math
.floor(Math
.random
() * symbols
.length
)]; }
function spin() {
if (isSpinning) return;
isSpinning = true;
result.textContent = '';
let spins = 0;
const spinInterval = setInterval(() => {
reels.forEach(reel => {
reel.textContent = getRandomSymbol();
reel.style.transform = `rotate(${Math.random() * 10 - 5}deg)`;
});
}, 50);
setTimeout(() => {
clearInterval(spinInterval);
const finalSymbols = [];
reels.forEach(reel => {
const symbol = getRandomSymbol();
reel.textContent = symbol;
finalSymbols.push(symbol);
reel.style.transform = 'rotate(0deg)';
});
isSpinning = false;
checkWin(finalSymbols);
}, 2000);
}
function checkWin(symbols) {
if (symbols[0] === symbols[1] && symbols[1] === symbols[2]) {
result.textContent = '🎉 Jackpot! You win! 🎉';
} else if (symbols[0] === symbols[1] || symbols[1] === symbols[2] || symbols[0] === symbols[2]) {
result.textContent = '😊 Small win! Try again!';
} else {
result.textContent = '😢 Try again!';
}
}
spinBtn.addEventListener('click', spin);
</script>
</body>
</html>