Created
June 29, 2024 01:54
-
-
Save SH20RAJ/5d329734710c050260977c05b7daff2b to your computer and use it in GitHub Desktop.
Head or Tails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Flip a Coin</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
height: 100vh; | |
margin: 0; | |
background-color: #f0f0f0; | |
} | |
.container { | |
text-align: center; | |
} | |
h1 { | |
color: #333; | |
} | |
.coin { | |
width: 100px; | |
height: 100px; | |
background-color: #ddd; | |
border-radius: 50%; | |
margin: 20px auto; | |
position: relative; | |
overflow: hidden; | |
} | |
.coin::before, | |
.coin::after { | |
content: ''; | |
position: absolute; | |
width: 100%; | |
height: 50%; | |
background-color: #f0f0f0; | |
top: 0; | |
left: 0; | |
z-index: 1; | |
} | |
.coin::after { | |
bottom: 0; | |
} | |
.coin .result-text { | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
font-size: 24px; | |
font-weight: bold; | |
color: #333; | |
opacity: 0; | |
transition: opacity 0.3s ease-in-out; | |
} | |
.coin.flipped .result-text { | |
opacity: 1; | |
} | |
button { | |
padding: 10px 20px; | |
font-size: 16px; | |
cursor: pointer; | |
background-color: #007bff; | |
color: white; | |
border: none; | |
border-radius: 4px; | |
transition: background-color 0.3s ease; | |
} | |
button:hover { | |
background-color: #0056b3; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<h1>Flip a Coin</h1> | |
<div class="coin" id="coin"> | |
<span class="result-text" id="resultText"></span> | |
</div> | |
<button onclick="flipCoin()">Flip Coin</button> | |
</div> | |
<script> | |
function flipCoin() { | |
var coin = document.getElementById('coin'); | |
var resultText = document.getElementById('resultText'); | |
coin.classList.remove('heads', 'tails'); | |
resultText.textContent = ''; | |
// Randomly decide heads or tails | |
var random = Math.random(); | |
var result = random < 0.5 ? 'heads' : 'tails'; | |
coin.classList.add(result); | |
resultText.textContent = result.toUpperCase(); | |
// Trigger animation | |
coin.classList.add('flipped'); | |
// Reset animation after 1s | |
setTimeout(function () { | |
coin.classList.remove('flipped'); | |
}, 1000); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment