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

236
Views
Daily info using setTimeout?

How can I use setTimeout to display a new Text daily, every 24 hours The code below is wrong It's just to draw attention to the images I want to display enter image description here

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

0

Dont use setTimeout function if you want to show quotes daily because when you will close your application then setTimeout will vanished as it will not run in background or when you will reload App then it will also reset. So its not good practice to use it for that purpose. If you want to show random quotes daily then make a backend and here you have to write CRON Job for it which will be executed after 24 hours and save quotes in your DB. And then load these quotes (by making backend route) from your DB on client side. However if you want to use the background timers then use them instead of setTimeout.

about 4 years ago · Juan Pablo Isaza Report

0

As Asad Haroon suggested, you may use crontab with a cronjob that looks something like this: 0 0 * * * or @daily. Apart from that, you may consider using anacron as well if you are not sure your backend runs non-stop 24/7 (but the config is different then).

But I want to suggest another implementation. You can try to record the last time (like formatted new Date()) your user opened the website and saw the quote. If you don't have a backend, you can store it using localStorage: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

Once the user opens the website again, you check if 24 hours has passed since the last quote update. Say, subtract one date and time from the other. If it has, update the quote. Otherwise, don't do anything.

To summarize, make this calculation every time your user opens the website and check if 24 hours has passed since the last quote update by subtracting current date and time from the last quote update ones.

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!