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

210
Views
How to Add Extend Time from 30 seconds to 4,5,6,7..... minutes in JavaScript Countdown

Someone has created a countdown timer and I am trying to add more minutes into the existing timer to extend the timer. But an error occurs, it only countdowns from 30 seconds

<p id="demo"></p>

<script>
var time = 30; // This is the time allowed
var saved_countdown = localStorage.getItem('saved_countdown');

if(saved_countdown == null) {
    // Set the time we're counting down to using the time allowed
    var new_countdown = new Date().getTime() + (time + 2) * 1000;

    time = new_countdown;
    localStorage.setItem('saved_countdown', new_countdown);
} else {
    time = saved_countdown;
}

// Update the count down every 1 second
var x = setInterval(() => {

    // Get today's date and time
    var now = new Date().getTime();

    // Find the distance between now and the allowed time
    var distance = time - now;

    // Time counter
    var counter = Math.floor((distance % (1000 * 60)) / 1000);

    // Output the result in an element with id="demo"
    document.getElementById("demo").innerHTML = counter + " s";
        
    // If the count down is over, write some text 
    if (counter <= 0) {
        clearInterval(x);
        localStorage.removeItem('saved_countdown');
        document.getElementById("demo").innerHTML = "EXPIRED";
    }
}, 1000);
</script>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I couldn't run your snippet. Here is another approach. A simpler one. Try it.

const root = document.getElementById('root')

let minutes = 30
let seconds = minutes * 60
let interval_ms = 1000 

let interval = setInterval(() => {
  root.innerHTML = 'minutes ' + Math.ceil(seconds/60) + '<br> seconds ' + seconds
  seconds -= 1
  if(seconds < 0) clearInterval(interval)
}, interval_ms)
<div id="root"></div>

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!