0

javascript image slider i cant find a way to debug sorry for noob question

so I am just starting on my first javascript project. i am trying to make an image slider and its not going well. i wrote this code and although there is no visible bugs i can't get it to work can anyone explane why this code is not working please. var arr = ["slideshow1.jpg","slideshow2.jpg","slideshow3.jpg"] var num = 0 function show(){ while (num = arr.length) { num++ document.getElementById(ssc); ssc.src = arr[num]; } } setInterval(show(),3000);

17th Mar 2017, 11:58 PM
Maurizio Borg
Maurizio Borg - avatar
2 ответов
+ 1
First off there are some semicolons you need to add. But the main problem is in your while loop, the condition is num = arr.length = is the assignment operator and == should be used for checking if two values are equal. Also, the while loop would never run because num == arr.length is never met. You should use another operator, and for what I think you are trying to do, you should use the < operator. The last problem is with the line: document.getElementById(ssc) It should be: var ssc = document.getElementById("ssc"); This is because the getElementById method returns an element so you have to assign it to a variable. Also, you needed quotes around the id parameter.
18th Mar 2017, 12:13 PM
Alex Mulligan
0
Thx man really halps :)
18th Mar 2017, 3:41 PM
Maurizio Borg
Maurizio Borg - avatar