0
Why isn't this code working?
HTML: <!DOCTYPE html> <html> <head> <title>Doggo Studies WebPage</title> <body><div> <img id="doggo" src="doggo.jpg" width="200px" height="200px"/><button onclick="Next()"> Next Doggo</button></div> </html> JavaScript: function Next() { var pepe = document.getElementById("doggo"); var images = ["doggo.jpg", "doggo2.jpg", "doggo3.jpg"]; for (var i = 0; i < images.length; i++) { if i >= images.length) { i = 0; doggo.src = images[num]; } } } I was training while studying the JavaScript module, and this code doesn't work. I made the HTML part work with the image and the button, but why doesn't it manage to load the other image files when i click the button?
1 Answer
+ 3
https://code.sololearn.com/WRG1F0mANW0X/?ref=app
here I've written code that changes background color, the same way you can change images