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

265
Views
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 answers
Answer question

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 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!