Skip to content

Commit 8085b80

Browse files
committed
Sem MVP
1 parent 13e3a94 commit 8085b80

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎assignments/closure.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@ kingdom('Westeros');
1919
// ==== Challenge 2: Create a counter function ====
2020
const counter = () => {
2121
// Return a function that when invoked increments and returns a counter variable.
22+
let count = 0;
23+
return function() {
24+
count++;
25+
return count;
26+
}
2227
};
28+
let newCounter = counter();
2329
// Example usage: const newCounter = counter();
2430
// newCounter(); // 1
2531
// newCounter(); // 2
32+
console.log(newCounter());
33+
console.log(newCounter());
2634

2735

2836

0 commit comments

Comments
 (0)