Creating images sliders in JS
I'm trying to create a Previous and a Next button to change the image, the Next button works, but not the Previous button. The first code shown has something wrong that creates a problem which JS says is "Uncaught ReferenceError: prev is not defined" the second one is correct but I can't find a difference between these codes can anyone help, please? The HTML is correct the problem is probably somewhere in the JS Code 1 (incorrect): var images = [ 'http://www.sololearn.com/uploads/slider/1.jpg', 'http://www.sololearn.com/uploads/slider/2.jpg', 'http://www.sololearn.com/uploads/slider/3.jpg' ]; var num = 0; function next() { var slider = document.getElementById("slider"); num++; if(num >= images.length) { num = 0; } slider.src = images[num]; } function perv() { var slider = document.getElementById("slider"); num--; if(num < 0) { num = images.length-1; } slider.src = images[num]; } Code 2 (correct): var images = [ 'http://www.sololearn.com/uploads/slider/1.jpg', 'http://www.sololearn.com/uploads/slider/2.jpg', 'http://www.sololearn.com/uploads/slider/3.jpg' ]; var num = 0; 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; } slider.src = images[num]; } */ Here is the link to the program the incorrect code is a comment