Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda