Skip to content

Commit d0e9faa

Browse files
sofialevinsofialevin
authored andcommitted
Completed closure.js.
1 parent 2efd2ff commit d0e9faa

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎assignments/closure.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
// ==== Challenge 1: Write your own closure ====
22
// Write a simple closure of your own creation. Keep it simple!
33

4+
function increase() {
5+
let num1 = 0;
6+
function add(num2) {
7+
num1 = num1 + num2
8+
return num1
9+
}
10+
return add
11+
}
12+
13+
const increment = increase();
14+
15+
const c1 = increment(2)
16+
const c2 = increment(3)
17+
const c3 = increment(5)
18+
19+
console.log(c1, c2, c3)
420

521
/* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */
622

0 commit comments

Comments
 (0)