Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

324
Vistas
How to store countdown in local storage
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&nbsp;" + counter + "&nbsp;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!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda