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

163
Views
Generate only one word in the list everyday at midnight without repetition in JavaScript

May I ask if I have a list emotion=['happy','sad', 'hopeful', 'delighted', 'despite', 'satisfied', 'confused', 'bored', 'awe', 'curious'];

I want to generate only one word from the list at midnight only, without repetition (until it gets to the end of the list, then repeat again). For example, if yesterday I get on the HTML webpage and got the word 'happy', then the next day I will have to get a word that is different from 'happy', could be 'sad', but when many days go by (here we have 10 words so 10 days) there is no more word in the list, then it can get back to the beginning of the list or so. May I ask how could I do that in Javascript?

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

0

You could use the current date, along with the remainder operator (%) to get an incrementing, in-range index for each day. For example:

const emotions = ['happy','sad', 'hopeful', 'delighted', 'despite', 'satisfied', 'confused', 'bored', 'awe', 'curious'];

const dayNum = new Date().getDate();

const index = dayNum % emotions.length;

const todaysEmotion = emotions[index];

console.log(todaysEmotion);

Or, just:

emotions[new Date().getDate() % emotions.length];
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!