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

269
Vistas
I need my webpage to play random videos but the JS keeps repeating the same random video unless I refresh webpage

The HTML section loops but repeatedly plays the same randomly selected video selected by the JS. If I refresh the html it will play a different video. I would like it to choose a different random video after each delayms expires. I apologize, I am kind of new to programming and my terminology is off.

//HTML
{url:randvideo1, delayms:10000},

//video arrays found in JS

var videoArray1 = [
"v/video01.mp4",
"v/video02.mp4",
"v/video03.mp4",
"v/video04.mp4"
];

var randvideo1 = videoArray1[Math.floor(Math.random()*videoArray1.length)];
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're probably looking for setInterval which calls a function every given amount of time.

const delay = 3000;

var videoArray1 = [
  "v/video01.mp4",
  "v/video02.mp4",
  "v/video03.mp4",
  "v/video04.mp4"
];

function playVideo() {
  var randvideo1 = videoArray1[Math.floor(Math.random() * videoArray1.length)];
  
  console.log(`Playing video ${randvideo1} for ${delay / 1000} seconds...`)
  
  /* 
    The rest of your code to set the new video source in the html.
  */
}

setInterval(playVideo, delay);

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