File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed
Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change 55/* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */
66
77
8- // ==== Challenge 2: Create a counter function ====
9- const counter = ( ) => {
10- // Return a function that when invoked increments and returns a counter variable.
8+ // ==== Challenge 2: Implement a "counter maker" function ====
9+ const counterMaker = ( ) => {
10+ // IMPLEMENTATION OF counterMaker:
11+ // 1- Declare a `count` variable with an value of 0. We will be mutating it, so declare it using `let`!
12+ // 2- Declare a function `counter`. It should increment and return `count`.
13+ // NOTE: This `counter` function, being nested inside `counterMaker`,
14+ // "closes over" the`count` variable. It can "see" it in the parent scope!
15+ // 3- Return the `counter` function.
1116} ;
12- // Example usage: const newCounter = counter ();
13- // newCounter (); // 1
14- // newCounter (); // 2
17+ // Example usage: const myCounter = counterMaker ();
18+ // myCounter (); // 1
19+ // myCounter (); // 2
1520
16- // ==== Challenge 3: Create a counter function with an object that can increment and decrement ====
21+ // ==== Challenge 3: Make `counterMaker` more sophisticated ====
22+ // It should take a `limit` argument. Any counters we make with `counterMaker`
23+ // will refuse to go over the limit, and start back at 1.
24+
25+ // ==== Challenge 4: Create a counter function with an object that can increment and decrement ====
1726const counterFactory = ( ) => {
1827 // Return an object that has two methods called `increment` and `decrement`.
1928 // `increment` should increment a counter variable in closure scope and return it.
You can’t perform that action at this time.
0 commit comments