• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

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

 
Ranch Hand
Posts: 190
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: 190
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

 
Marshal
Posts: 67313
170
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?"
 
Space pants. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!