Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

323
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!