Skip to content

Commit aae5f2d

Browse files
committed
done closure challenge
1 parent d815072 commit aae5f2d

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎assignments/closure.js‎

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

4+
let outside ="i am outsite the function";
5+
function closure() {
6+
let inside = "I am inside this function";
7+
console.log(outside);
8+
console.log(inside) ;
9+
};
10+
//console.dir(closure);
411

512
// ==== Challenge 2: Create a counter function ====
613
const counter = () => {
714
// Return a function that when invoked increments and returns a counter variable.
15+
let count =0;
16+
17+
return function () {
18+
console.log(count);
19+
return count++;
20+
}
821
};
22+
const counterOne = counter();
23+
counterOne();
24+
counterOne();
25+
counterOne();
26+
counterOne();
927
// Example usage: const newCounter = counter();
1028
// newCounter(); // 1
1129
// newCounter(); // 2

0 commit comments

Comments
 (0)