+ 1

What's wrong here? JavaScript

Hello, I'm tying to see the lenght of the var when it works. What's wrong with this code? Thanks. HTML: <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <div> <button onclick="prev()"> Prev </button> <img id="slider" src="http://www.sololearn.com/uploads/slider/1.jpg" width="200px" height="100px"/> <button onclick="next()"> Next </button> </div> <div> <p id= "log" > </p> </div> </body> </html> JAVASCRIPT: var images = [ 'http://www.sololearn.com/uploads/slider/1.jpg', //0 'http://www.sololearn.com/uploads/slider/2.jpg', //1 'http://www.sololearn.com/uploads/slider/3.jpg' //2 ]; var num = 0; var log = document.getElementById('log'); function next() { var slider = document.getElementById('slider'); num++; if(num >= images.length) { num = 0; } slider.src = images[num]; } function prev() { var slider = document.getElementById('slider'); num--; if(num < 0) { num = images.length-1; log.innerHTML = images.length; } slider.src = images[num]; }

31st Mar 2017, 6:32 AM
Luis Eduardo LĂłpez Andrade
Luis Eduardo LĂłpez Andrade - avatar
1 Answer
0
everything is working fine
31st Mar 2017, 7:24 AM
Yaroslav Pieskov
Yaroslav Pieskov - avatar