I have 3 images in an array and I randomise the index to generate them randomly but I want to generate each image 4 times. What would be the most efficient way of doing this?
Edit (Full Code):
var image_array = ["image1.png", "image2.png", "image3.png"];
function set_page()
{
var table = document.getElementById("grid");
if(table != null)
{
for(var i = 0; i < table.rows.length; i++)
{
for(var j = 0; j < table.rows[i].cells.length; j++)
{
table.rows[i].cells[j].onclick = function() {
click_cell(this);
}
//table.rows[i].cells[j].style.backgroundImage = "url('../images/back.png')";
add_cell_image(table.rows[i].cells[j]);
}
}
}
}
function click_cell(cell)
{
}
function add_cell_image(cell)
{
for(var i = 0; i <= image_array.length; i++)
{
for(var j = 0; j <= image_array.length; j++)
{
var index = create_values();
cell.innerHTML = "<img class='cell_image' align='middle' width='90' height='90' src ='../images/" + image_array[index] + "'/>";
}
}
}
function create_values()
{
return Math.floor(Math.random() * image_array.length);
}