random/index.html

80 lines
2.4 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;
let previousRandomNumber = null;
function generateRandomNumber() {
let randomNumber;
// Keep generating a random number until it's different from the previous one
do {
randomNumber = Math.floor(Math.random() * (12 - 1 + 1)) + 1;
} while (randomNumber === previousRandomNumber);
previousRandomNumber = randomNumber; // Update previousRandomNumber
randomNumberElement.textContent = randomNumber; // Display the new random number
}
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
generateRandomNumber();
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>