82 lines
2.3 KiB
HTML
82 lines
2.3 KiB
HTML
<!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 with Countdown</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
background-color: #3f3f3f;
|
|
}
|
|
#randomNumber {
|
|
font-size: 384px;
|
|
padding: 40px;
|
|
background-color: #4CAF50;
|
|
color: white;
|
|
border-radius: 10px;
|
|
margin-bottom: 20px;
|
|
width: 50%;
|
|
text-align: center;
|
|
font-weight: bold;
|
|
}
|
|
#countdown {
|
|
font-size: 24px;
|
|
font-weight: bold;
|
|
color: #999;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div id="randomNumber">Loading...</div>
|
|
<div id="countdown">Next refresh in: loading...</div>
|
|
|
|
<script>
|
|
const countdownElement = document.getElementById('countdown');
|
|
const randomNumberElement = document.getElementById('randomNumber');
|
|
|
|
let countdownTime;
|
|
|
|
function generateRandomNumber() {
|
|
const min = 1;
|
|
const max = 12;
|
|
const randomNumber = Math.floor(Math.random() * (max - min + 1)) + min;
|
|
}
|
|
|
|
function setRandomNumber() {
|
|
const prevNumber = randomNumber;
|
|
while (prevNumber == randomNumber) {
|
|
generateRandomNumber();
|
|
}
|
|
randomNumberElement.textContent = randomNumber;
|
|
}
|
|
|
|
function updateCountdown() {
|
|
if (countdownTime <= 0) {
|
|
generateRandomNumber();
|
|
// Generate a new random countdown time between 10 and 30 seconds
|
|
countdownTime = Math.floor(Math.random() * (30 - 10 + 1)) + 10;
|
|
} else {
|
|
countdownElement.textContent = `Next refresh in: ${countdownTime} seconds`;
|
|
countdownTime--;
|
|
}
|
|
}
|
|
|
|
// Generate an initial random number and countdown time
|
|
setRandomNumber();
|
|
countdownTime = Math.floor(Math.random() * (30 - 10 + 1)) + 10; // Initial random countdown
|
|
|
|
// Update countdown and refresh the number every second
|
|
setInterval(updateCountdown, 1000);
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|
|
|