I want to modify my jQuery code please help. this is countdown timer start from 30 and end on 0 and then its stop.
I want when my countdown on 0 then its start again from 30. I want randomly countdown from 30 to 0 and then start 30 to 0.
// Random Countdown Timer Script, by http://ctrtard.com
var timer;
function startCount() {
timer = setInterval(count, 1000); // 200 = 200ms delay between counter changes. Lower num = faster, Bigger = slower.
}
function count() {
var rand_no = Math.ceil(1 * Math.random()); // 9 = random decrement amount. Counter will decrease anywhere from 1 - 9.
var el = document.getElementById('counter');
var currentNumber = parseFloat(el.innerHTML);
var newNumber = currentNumber - rand_no;
if (newNumber > 0) {
el.innerHTML = newNumber;
} else {
el.innerHTML = "Sold Out"; // This message is displayed when the counter reaches zero.
}
}
function count() {
var rand_no = Math.ceil(1 * Math.random()); // 9 = random decrement amount. Counter will decrease anywhere from 1 - 9.
var el = document.getElementById('counter');
var currentNumber = parseFloat(el.innerHTML);
var newNumber = currentNumber - rand_no;
if (newNumber > 0) {
el.innerHTML = newNumber;
} else {
setElemVal(el , 30);
count();
}
}
function setElemVal(el , val) {
el.innerHTML = '';
el.innerHTML = val;
}
Just add another function to reset the value and change the else
condition.