How can we let a button generate a random video from a pool of listed HTML iframes? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can we let a button generate a random video from a pool of listed HTML iframes?

Goal: To create a button that will show contents within ONE random set of <li></li> once clicked. --> In my case, there is a video and some text within each pair of <li></li> tags. Please refer to code below. Code: https://code.sololearn.com/WdXitg835otG/#html I would like to create a button like either of these: 1) https://www.randomanime.org --> the orange "Generate Random List" button 2) https://random-ize.com/random-youtube/ --> the grey "Generate Another!" button Any help would be greatly appreciated!

19th Sep 2020, 8:38 PM
Solus
Solus - avatar
2 Answers
0
Try using Math.random()*length of array containing all html frames
19th Sep 2020, 8:59 PM
Abhay
Abhay - avatar
0
Abhay How can we put HTML frames inside a JavaScript array? As of now, I've done the following: <!DOCTYPE HTML> <html> <head> </head> <body style = "text-align:center;"> <br> <button id = "button" onclick = "random_element()">click here</button> <h1 style = "color:pink;"> Project Title</h1> <hr> <hr> <hr> <p id = "ZZZ" style = "font-size: 14px; color: #a8bcff;"></p> <script> var zzz = document.getElementById('ZZZ'); var arr = ["aaa", "xxx", "ccc", "vvv"]; function random_element() { zzz.innerHTML = arr[Math.floor(Math.random() * arr.length)]; } </script> <hr> <hr> <hr> </body> </html> As you can see, I understand how to generate random elements in the form of text. But I don't know how to "make array contain all html frames" like you've mentioned above.
20th Sep 2020, 12:14 AM
Solus
Solus - avatar