samedi 6 juin 2020

Random image without repeat

hello can you help me for this problem: when I click on the image, the image changes randomly, but it happens that some images are repeated after the click. how can i solve it? below is my queue. thank you very much

'''

let h1 = document.querySelector('h1')
let bigSquare = document.createElement('div')
bigSquare.id = 'bigSquare'
h1.after(bigSquare)

let images = ['01.jpg', '02.jpg', '03.jpg', '04.jpg', '05.jpg']

let randomImage = function(){
   return (Math.round(Math.random()*(images.length-1)))
}

let image = document.createElement('img')
bigSquare.append(image)
image.src = images[randomImage()]

image.onclick = function(event){
   event.target.src = images[randomImage()]
}

'''




Aucun commentaire:

Enregistrer un commentaire