function counter1() {
var counter = 5;
setInterval(function() {
counter--;
if (counter >= 0) {
var id = document.getElementById("res");
var bet = document.getElementById("pts");
var on = document.getElementById("bet");
var beth = document.getElementById("beth");
var betv = document.getElementById("betv");
id.innerHTML = "Results after " + counter + " seconds";
beth.disabled = true;
beth.style.backgroundColor = "rgb(229, 229, 229)";
betv.disabled = true;
betv.style.backgroundColor = "rgb(229, 229, 229)";
beth.style.cursor = 'none';
betv.style.cursor = 'none';
}
if (counter == 0) {
counter2();
var beth = document.getElementById("beth");
var betv = document.getElementById("betv");
beth.disabled = false;
beth.style.backgroundColor = "#4CAF50";
betv.disabled = false;
betv.style.backgroundColor = "#008CBA";
beth.style.cursor = 'pointer';
betv.style.cursor = 'pointer';
var random = Math.floor((Math.random() * 100) + 1);
var id1 = document.getElementById("res1");
if (random < 50) {
id1.innerHTML = "Heroes have won" + random;
} else {
id1.innerHTML = "Villains have won" + random;
}
}
}, 1000);
}
function counter2() {
var counter = 5;
var on = document.getElementById("bet");
setInterval(function() {
counter--;
if (counter == 9) {
on.innerHTML = "";
}
if (counter >= 0) {
id = document.getElementById("res");
var bet = document.getElementById("pts");
id.innerHTML = "Bet within " + counter + " seconds";
}
if (counter == 0) {
counter1();
}
}, 1000);
}
I want this code to be stored in local storage ( countdown) ,,I want those countdown to be retrieved on page load, would appreciate if I could get some suggestions or if anyone could modify the code. is it possible to modify it from here to store countdown in local storage or should I recode from the beginning would appreciate on suggestions and ideas. Thank you!
you can store value in local system.
to set the value of any variable then use
localStorage.setItem(key, value);
syntax to set a value in a local variable. here "key" means variable name and "value" means its value which you want to assign.
// to read data of local storage
let lastname = localStorage.getItem(key);
to get data of a variable you have to use above code. here in "key" means you have to provide variable name which you used at a time of assignment.
for more information please check out this link for more information click here