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?
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];