Simple HTML Coin Flip Game - Play Now!
<!DOCTYPE html>
<html>
<head>
<title>Coin Flip</title>
<script>
// Create a function for the coin flip
function flipCoin(){
// Get a random number between 0 and 1
let coinResult = Math.round(Math.random());
<pre><code> // Check if result is 0 or 1 and display the result
if (coinResult === 0){
alert('Heads');
} else {
alert('Tails');
}
}
</script>
</head>
<body>
<h1>Coin Flip</h1>
<p>Click the button below to flip a coin!</p>
<button onclick='flipCoin()'>Flip Coin</button>
</body>
</code></pre>
</html>
原文地址: https://www.cveoy.top/t/topic/lml1 著作权归作者所有。请勿转载和采集!