<html>
<body>
<center>
<h1>ROCK PAPER SCISSOR</h1>
<!-- Scoreboard -->
<h3>🏆 Scoreboard</h3>
<p>Wins: <span id="wins">0</span></p>
<p>Losses: <span id="losses">0</span></p>
<p>Draws: <span id="draws">0</span></p>
<!-- Game Buttons -->
<button onclick="play('rock')">ROCK</button>
<button onclick="play('paper')">PAPER</button>
<button onclick="play('scissor')">SCISSOR</button>
<!-- Results Display -->
<p id="result"></p>
<p id="details"></p>
<script>
// Score counters
let wins = 0;
let losses = 0;
let draws = 0;
// Function to generate random AI choice
function generateAIChoice() {
const choices = ["rock", "paper", "scissor"];
return choices[Math.floor(Math.random() * 3)];
}
// Main play function
function play(playerChoice) {
const aiChoice = generateAIChoice();
let resultText = "";
if (playerChoice === aiChoice) {
resultText = "🤝 It's a Draw!";
draws++;
document.getElementById("draws").innerText = draws;
} else if (
(playerChoice === "rock" && aiChoice === "scissor") ||
(playerChoice === "paper" && aiChoice === "rock") ||
(playerChoice === "scissor" && aiChoice === "paper")
) {
resultText = "🎉 You Won!";
wins++;
document.getElementById("wins").innerText = wins;
} else {
resultText = "💥 You Lost!";
losses++;
document.getElementById("losses").innerText = losses;
}
// Show result and choices
document.getElementById("result").innerText = resultText;
document.getElementById("details").innerHTML =
"AI chose: " + aiChoice + "<br>Your choice: " + playerChoice;
}
</script>
</center>
</body>
</html>