<!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');
			}
		}
	&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;h1&gt;Coin Flip&lt;/h1&gt;
	&lt;p&gt;Click the button below to flip a coin!&lt;/p&gt;
	&lt;button onclick='flipCoin()'&gt;Flip Coin&lt;/button&gt;
&lt;/body&gt;
</code></pre>
</html>

原文地址: https://www.cveoy.top/t/topic/lml1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录