100-project-100-days-website/100_projects/28-show-random-image-every-x-second/main.js
2023-03-21 17:10:48 +03:00
Ask

21 lines
559 B
JavaScript

{43119d012b03c33e3e9aa6794cc525004203208c true 559 main.js 0xc001dfb260}

var myElement = document.getElementById('myImg'),
myImgs = [
'imgs/01.jpg',
'imgs/02.jpg',
'imgs/03.jpg',
'imgs/04.jpg',
'imgs/05.jpg',
'imgs/06.jpg',
'imgs/07.jpg',
'imgs/08.jpg'
];
function changeImage(myElement, myImgs){
'use strict';
setInterval(function () {
var myRandomNum = Math.floor(Math.random() * myImgs.length);
console.log(myRandomNum)
myElement.src = myImgs[myRandomNum];
}, 1000);
}
changeImage(myElement, myImgs);