+ 1
How to increment the counter every second? The increment should not stop even when I refresh it on browser.
I'm writing a .JS program that increments every second and shud keep on running because this is not something connected to browser. I have an admin page created and I have created a sample user page. I'm planning to place this .JS file in my user's. Any help how to do it.
16 Answers
+ 2
Here you go
Added Pause/Start button
https://code.sololearn.com/W7B3k8ZufM16/?ref=app
This solution is not perfect, you should implement localStorage to store timer variable for each different users.
Currently the timer resume value is jumping to current time tracking due to not keeping track of counter previously paused value.
+ 10
Interesting solution by @Calvin again!
@Muthiah basically it compute the relative time from a predefined moment and that's why it's able to persist the counter. Otherwise you'll need to store it somewhere else like @Baptiste mentioned. 😉
+ 4
For different increment, you need to multiply an increment constant with counter value.
https://code.sololearn.com/WYKLBfHPP5Kj/?ref=app
+ 3
@Zephyr
Thank you for the explanations. 👍🏼
@Muthiah
If you need to save local file counter status, you could use localStorage.
+ 2
I am not proficient with JS, but you could save a file with the count every seconds and try to read it first when you load your page
You could add the date of when the second occured so that you start again at 0 if it was too long ago
+ 2
Thank you so much! :) @Calvin
+ 2
I cannot thank you enough!! Thanks a ton!! @Calvin
+ 1
Thank you! @Calvin! Can you kindly explain me, please!?
+ 1
Oh okay!! now I get it!! Thank you! @Zephry
+ 1
You need to add pause and resume timer.
I try to look into it later.
0
How to save a file with the count every second?
0
I have another doubt what if I have to increment a variable by 0.0018 every second. how should I do it? (PS: I am a newbie to JS)
0
I'm really sorry to bother again and again only after getting to understand all this I am getting doubts. What if I had to stop this at a certain time stamp!? And also can you kindly let me know how shud I place this in the user dashboard and have control over it in the admin page?
0
Thank you once again @Calvin. I will also try and will get back to you. Good day! :)
0
@Calvin how to set up a start time button after inserting the time stamp and place it in a DB?