Il setTimeout restituisce un timerID che serve se devi eliminare un timeout prima della sua esecuzione.
Tu come timerID del setTimeout hai usato la variabile "animation" che ha lo stesso nome della tua funzione "animation()"
Forse volevi fare una funzione ricorsiva?
codice:var pos=1; function animation(){ if(pos=="" || pos==4){ pos=1; } else { pos++; } alert(pos); setTimeout(animation, 5000); } animation();![]()

Rispondi quotando