Countdown timer resets

Hello I got a countdown timer for my website but when I use refresh it resets the timer for some reason.
I can give you the urls. Also I don’t know where to go to set a new date for the timer to end on. I’d really appreciate it if you helped. Thank you.

https://www.villaincorp.net/dark/countdown/site.js
https://www.villaincorp.net/dark/countdown/vendor/flipclock/flipclock.js

I’ll provide anything I need to. I’m completely stumped at how to fix this.

Some code would be better than 404 pages. ;-)

JS doesn’t remember its state but evaluates anew each time you (re-)load a page. However, you can persist data to the sessionStorage for this sort of things; a countdown might then look like

const start = sessionStorage.start || Date.now()
const timespan = 60000
const delay = 1000

function countdown () {
  const now = Date.now()

  document.body.textContent = Math.floor((now - start - timespan) / 1000)

  if (now - start < timespan) {
    setTimeout(countdown, delay)
  } else {
    alert('Time\'s up!')
    delete sessionStorage.start
  }
}

if (!sessionStorage.start) {
  sessionStorage.start = start
}

countdown()

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.