Randomised video selector | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Randomised video selector

Does anyone know how I can make it possible for a video to be picked at random (out of a selection of 3) when someone enters the website?

25th Nov 2018, 2:22 AM
OL Thomas
OL Thomas - avatar
2 Answers
+ 5
You can use JavaScript random function to generate random numbers which you can use as index to choose from an array of video URLs. // an array of video URLs var videoURLs = ["video1.mp4","video2.mp4","video3.mp4"]; // pick random video URL to use var URL = videoURLs[Math.floor(Math.random() * 3)]; Hth, cmiiw
25th Nov 2018, 6:34 AM
Ipang
+ 2
use JavaScript function
25th Nov 2018, 7:35 AM
UwU Discover Me