I want to randomly loop all the images that is present in a folder. Currently I'm able to manually enter each image one by one and it displays. But I want the function to display images by itself from a given folder.
JS
function rndmImg() {
var qs = [
{
text: "1",
img: "/Images/1.png"
},
{
text: "2",
img: "/Images/2.png",
},
{
text: "3",
img: "/Images/3.png",
},
{
text: "4",
img: "/Images/4.png",
},
{
text: "5",
img: "/Images/5.png",
},
];
var q = qs[Math.floor(Math.random() * qs.length)];
document.getElementById("q").innerHTML =
'<p>' + q.text + '</p>' +
'<img src="' + q.img + '">';
}
HTML
<div id="quote"></div>
<input class="Click me" style="float: left;" type="button"
value="Randomize" onclick="rndmImg()">