Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

168
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda