joeysusssex123
New Coder
Hi all, i am very new to javascript so bare with me. I am trying to build a very basic random image generator (for practice) but am having trouble with my code. This is what I have so far. I can do it so it changes colours but not images and i am struggling to understand why.
Any help would be appreciated.
Thanks
Joe
Code:
const button = document.querySelector('button')
const wrapper = document.querySelector('wrapper')
const background = ['images/italy1.avif','images/italy2.avif', 'images/italy3.avif', 'images/italy4.avif', 'images/italy5.avif', 'images/italy6.avif']
wrapper.style.background = "images/italy2.avif"
button.addEventListener('click', clickMe);
function clickMe(){
const ranim = parseInt(Math.random()*background.length)
wrapper.style.background = background[ranim]
}
Any help would be appreciated.
Thanks
Joe