简体   繁体   中英

How do I wait before executing the next line of code?

I need the script to stop and wait 3 seconds before executing the code that follows ( console.log('2 select question') ).


var i = 0,
    count = 5;
function f() {

    if (i < count) {
        i++;
        console.log('Continue 1')
        setTimeout(f, 1000);

    } if (i >= count) {
        console.log('2 select question')
        console.log('3 select answer')
        i = 0;
    }
}
f();

Hello I don't know if i undrestand you but try this :

var i = 0,
    count = 5;
function f() {

    if (i < count) {
        i++;
        console.log('Continue 1')
        setTimeout(f, 1000);

    } 
   else if (i >= count) {
        console.log('2 select question')
        console.log('3 select answer')
        i = 0;
    }
}
f();

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