<!DOCTYPE html>
<html>
<head>
<title>Gamble With Friends</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; margin: 50px; }
.game-area { border: 2px solid #333; padding: 20px; max-width: 400px; margin: auto; }
input { padding: 8px; margin: 5px; }
button { padding: 8px 16px; cursor: pointer; }
#result { margin-top: 15px; font-weight: bold; }
</style>
</head>
<body>
<div class="game-area">
<h1>Gamble With Friends</h1>
<label>Bet Amount ($): </label>
<input type="number" id="bet" min="5" max="100" value="10">
<br><br>
<label>Choose Number (1–10): </label>
<input type="number" id="choice" min="1" max="10" value="1">
<br><br>
<button onclick="playGame()">Bet!</button>
<p id="result"></p>
</div>
 
<script>
let balance = 100;
 
function playGame() {
const bet = parseInt(document.getElementById('bet').value);
const choice = parseInt(document.getElementById('choice').value);
const computerChoice = Math.floor(Math.random() * 10) + 1;
const resultEl = document.getElementById('result');
 
resultEl.innerHTML = `Your Number: ${choice}<br>Computer's Number: ${computerChoice}`;
 
if (choice === computerChoice) {
balance += bet;
resultEl.innerHTML += `<br>>> You won! +$${bet}`;
} else if (Math.abs(choice - computerChoice) === 1) {
resultEl.innerHTML += `<br>>> Very close! No win.`;
} else {
balance -= bet;
resultEl.innerHTML += `<br>>> You lost! -$${bet}`;
}
 
resultEl.innerHTML += `<br>Balance: $${balance}`;
 
if (balance <= 0) {
resultEl.innerHTML += `<br><h3>Game Over!</h3>`;
}
}
</script>
</body>
</html>