Create a Simple Random Number Game in HTML

Here's a basic example of a random game in HTML:

First, create a new HTML file and add the following code:

<!DOCTYPE html>
<html>
<head>
	<title>Random Number Game</title>
</head>
<body>
	<h1>Random Number Game</h1>
	<p>Click the button to generate a random number between 1 and 10:</p>
	<button onclick='generateRandom()'>Generate</button>
	<p id='result'></p>

	<script>
		function generateRandom() {
			var number = Math.floor(Math.random() * 10) + 1;
			document.getElementById('result').innerHTML = 'Your random number is: ' + number;
		}
	</script>
</body>
</html>

This code creates a button that, when clicked, generates a random number between 1 and 10 and displays it on the page.

You can customize this game by changing the range of the random number or adding new features, such as a timer or score system.

Have fun playing around with HTML and creating your own random game!

Create a Simple Random Number Game in HTML

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

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