I want to have a decreasing "spots remaining" script. Here is what I have so far. But the problem is that it goes negative. I want it to go down to 4 or 5 spots remaining and stop there.
<script type="text/javascript">
// This is in milliseconds
var delay_seconds = 12000
var female_count = 100
setInterval(function() {
// This is maximum number to increment count by
var increment_max = 1
// Get random number between 1 and increment_max
var rand_num = Math.floor(Math.random() * increment_max) + 1
// Add random number to current count
female_count -= rand_num
document.getElementById("random_number").innerHTML = female_count
}, delay_seconds)
</script>
Try this, it is a randomised countdown, stops at 1.
<!DOCTYPE HTML>
<html>
<head><title>Countdown</title></head>
<body>
<script type="text/javascript">
var count = 100;
function countdown() {
count -= 1;
if( count <= 0) {
count = 0;
xlearInterval(timer);
}};
(function loop() {
var rand = Math.round(Math.random() * (1000)) + 500;
setTimeout(function() {
countdown();
loop();
}, rand);
document.getElementById('seconds').innerHTML = count;
}());
</script>
<div id="seconds">100</div>
</body>
</html>
How can I slow it down? It's decreasing really quickly
i just modified zeno's script
starts at 12, counts down by 1 at a random rate of speed between 400-4000 milliseconds, and stops at 4
<script type="text/javascript">
var count = 12;
function countdown() {
count -= 1;
if( count <= 3) {
count = 3;
xlearInterval(timer);
}};
(function loop() {
var rand = Math.round(Math.random() * (4000)) + 400;
setTimeout(function() {
countdown();
loop();
}, rand);
document.getElementById('count').innerHTML = count;
}());
</script>
<div id="count">12</div>
Nice! Thanks man.
Last thing, how can I have them on the same line? I want to have 100 Spots Remaining right next to each other...currently it is 100 and spots remaining on the next line.
<div id="seconds">100</div>
Spots Remaining
Just change div to span!
<span id="seconds">100</span> Spots Remaining
Try something like 100 spots remaining
^^ lol thanks forum for evaluating that markup.
<div><span><span id="seconds">100</span> spots remaining</span></div>
Awesome! Thanks snipe