samedi 5 janvier 2019

setInterval for running a function with if statement not working

I need to use the setInterval function to run the function change() after every 3 seconds but what I have tried so far is not working:

    var image_tracker = '1gif' ; 
    function change() { 
     if(image_tracker =='1gif') { 
         image.src='2.gif' ; 
         image_tracker = '2gif' ; }
    else if (image_tracker ='2gif') { 
         image.src='3.gif' ; 
         image_tracker = '3gif' ; }
    else if (image_tracker = '3gif') {
         image.src='1gif' ; 
         image_tracker = '1gif' ; } }
    
    var timer = setInterval ('change () ; ' , 3000 ) ;
<img src="1.gif" id="gif1" alt="1.gif" style="width:400px;height:400px;border:1px solid black;">

Aucun commentaire:

Enregistrer un commentaire