while loop countdown javascript – JavaScript while loop examples as well as The while loop loops through a block of code as long as a specified condition is true.
while loop countdown javascript
first of all declare and instantiate your variable and then set up your loop that will run while your variable is greater than zero, log timer to the console for debugging purposes and reduce the count of timer by one over each iteration.
JavaScript while Loop
while (expression) { // statement }
javascript count down with wile loop
javascript count down with wile loop
var userCountDown = 60; while (userCountDown > 0) { console.log(userCountDown); userCountDown--; } //after userCountDown has reached zero, the code will break out of the while loop and run the alert with your confirmation message alert("Done");
JavaScript while loop examples
let userCountDown = 1; while (userCountDown < 10) { console.log(userCountDown); userCountDown +=2; }
create an array of five random number between 1 and 10
let rands = []; let userCountDown = 0; const base = 5; while(userCountDown < base) { rands.push(Math.round(Math.random() * 10)); userCountDown++; console.log('The Active base of the array is ' + userCountDown); } console.log(rands);
Results
The Active base of the array is 1 The Active base of the array is 2 The Active base of the array is 3 The Active base of the array is 4 The Active base of the array is 5 [1, 9, 1, 9, 6]
Don’t Miss : JQuery Tips And Tricks With Example
I hope you get an idea about while loop countdown javascript.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.