HTML code script for a Random number generator

Created on 3 July, 2024 • 115 views

HTML code script for a Random number generator

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Random Number Generator</title>

<script>

function generateNumber() {

 // Get a random number between 1 and 100 (modify the range as needed)

 const randomNumber = Math.floor(Math.random() * 100) + 1;

 // Display the number in the paragraph element

 document.getElementById("random-number").textContent = randomNumber;

}

</script>

</head>

<body>

 <h1>Random Number Generator</h1>

 <p id="random-number">Click the button to generate a random number.</p>

 <button onclick="generateNumber()">Generate</button>

</body>

</html>