fix(guide): simplify directory structure

This commit is contained in:
Mrugesh Mohapatra
2018-10-16 21:26:13 +05:30
parent f989c28c52
commit da0df12ab7
35752 changed files with 0 additions and 317652 deletions

View File

@ -0,0 +1,57 @@
---
title: How to Create a Countdown Timer
---
## How to Create a Countdown Timer
### Creation
Start by building the countdownTimer function.
```javascript
function startCountdown(seconds){
var counter = seconds;
var interval = setInterval(() => {
console.log(counter);
counter--;
if(counter < 0 ){
// The code here will run when
// the timer has reached zero.
clearInterval(interval);
console.log('Ding!');
};
}, 1000);
};
```
### Execution
Now to start the timer we provide `startCountdown()` with a number value as an argument which represents the seconds to countdown.
```javascript
startCountdown(10);
// Console Output //
// 10
// 9
// 8
// 7
// 6
// 5
// 4
// 3
// 2
// 1
// 0
// Ding!
```
### Live Example
<a href='https://codepen.io/rdev-rocks/pen/jLogxY?editors=0012' target='_blank' rel='nofollow'>Codepen - Countdown Timer</a>
### More Resources
Methods used:
* <a href='https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval' target='_blank' rel='nofollow'>setInterval()</a>
* <a href='https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearInterval' target='_blank' rel='nofollow'>clearInterval()</a>