-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClosure.js
More file actions
33 lines (27 loc) · 787 Bytes
/
Closure.js
File metadata and controls
33 lines (27 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Challenge: Write a countdown function with a hard-coded starting number inside closure
// Stretch goal: Write a countdown function that can count from a provided number,
// with a provided step
// Start
function countdown() {
let startingNum = 11
return function decrease() {
startingNum -= 1
return startingNum
}
}
const countingDown = countdown()
console.log(countingDown())
console.log(countingDown())
console.log(countingDown())
// Stretch goal
function countdown1(startingNumber, step){
let startingNum = startingNumber
return function decrease(){
startingNum -= step
return startingNum
}
}
const countingDown1 = countdown1(11, 1)
console.log(countingDown1())
console.log(countingDown1())
console.log(countingDown1())