Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

JS Timer goes into negative, and doesn't resume at given time

 
Ranch Hand
Posts: 199
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My use case is as follows:

I am already setting the following variables in localStorage.

bed-time.
wake-up time.


I need my count-down clock to stop at "bed time." It should visually display 00:00:00.

When it is time to "wake up," I want the count down to begin. It should now start counting down from 15:59 - The hours:minutes
remaining until it is time for bed-time again.

This repeats, over and over.

I wrote the following code:



This code and variations of it are either making my countdown timer go into the negative, stopping at 0:00, and not ever re-starting once it is time to wake-up.
 
Mark Richardson
Ranch Hand
Posts: 199
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a runnable snippet on codepen:

https://codepen.io/ammarrai/pen/RYbxpe

 
Sheriff
Posts: 67399
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have an idea what the code should be doing. Set breakpoints and see where the results go awry of your expectations. That might solve the problem for you. If not, it will give you line numbers to point to and ask "why is xyz happening here?"
 
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic