Skip to content

Commit e6ab9c9

Browse files
closure.js changed
1 parent 73d8a9a commit e6ab9c9

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

‎assignments/closure.js‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ top();
1818

1919

2020
// ==== Challenge 2: Create a counter function ====
21-
const counter = (num = 1) => {
22-
let count = (num) => {return num += 1; } count();
23-
// Return a function that when invoked increments and returns a counter variable.
21+
const counter = (num = 0) => {
22+
function count() {
23+
num ++;
24+
return num;
25+
}
26+
return count();
27+
// Return a function that when invoked increments and returns a counter variable.
2428
};
2529
// Example usage:
26-
const newCounter = counter();
27-
console.log(counter()); // should return 2.
30+
//const newCounter = counter();
31+
console.log(counter());
2832

2933

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

0 commit comments

Comments
 (0)