Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

332
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda