mardi 13 juillet 2021

How to print alphabet from A - Z. Each letter will be taken 3 second for print, only A will take 0 second?

When I try to execute by for loop & setTimeout method then got the output undefined. Then i tried to below method

var alphAbet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']


setTimeout(function loop() {
    console.log(alphAbet.shift());

    if (alphAbet.length){
        setTimeout(loop, 3000);
    }
}, 3000);

From A to Z all letters execute after 3 seconds. But based on the condition letter A will not take any time.

Aucun commentaire:

Enregistrer un commentaire