I have a small problem. I need to get 4 random images out of array of 6 elements but I don’t know how to do it. Images should repeat.
let array = ["../media/pawn.png", "../media/rook.png", "../media/knight.png", "../media/bishop.png", "../media/queen.png", "../media/king.png"];
shuffleArray(array);
array.forEach(function(image) {
let img = document.createElement('img');
img.src = image;
img.height = "45";
img.width = "50";
document.getElementById("random").appendChild(img);
});
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
let temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}