简体   繁体   中英

how to exit from a function in javascript?

I am using this codepen template https://codepen.io/stevethorson/pen/nisBh for quiz competition. I have 10 div elements all are set to display none except the first div, when this timer gets reset, it will change my next div display and hide the previous div display.

how to stop that timer resetting when it complete 10 resets and make my 10th div not to hide? all the id of div are in array. the changes i made at the bottom of js code in that template is,

var Timer;
let ids=["aq","bq","cq","dq","eq","fq","gq","hq","iq","jq"];
var i=0;
var j=1;
$(document).ready(function() {
    var callbackFunction = function(){
    Timer.reset(2);
   i+=1;
    j+=1;
   $('h3').html('Question Number:'+j+'');
   document.getElementById(ids[i-1]).style.display = "none";
    document.getElementById(ids[i]).style.display = "";
    };
 
Timer = new radialTimer(callbackFunction);
    Timer.init("timer", 2);
});

so i want my last div to appear permanently

Timer.start(t);
        while (j >2) {
     timer.stop(a); // name that callback function as a and if it gets incremented i,e resetted untill some reseets, just use  while loop and stop that funcion a.
    }
        }
    }
    
    var Timer;
    let ids=["aq","bq","cq"];
    var i=0;
    var j=1;
    
    $(document).ready(function() {
        var callbackFunction = function(a){    //function a
        Timer.reset(2);
       i+=1;
        j+=1;
       $('h3').html('Question:'+j+'');
       document.getElementById(ids[i-1]).style.display = "none";
                      document.getElementById(ids[i]).style.display = "";
        };
     
    Timer = new radialTimer(callbackFunction);
        Timer.init("timer", 2);
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM