Skip to content

Commit 6808f67

Browse files
Barbara HunterBarbara Hunter
authored andcommitted
changes to closure.js
1 parent d192ca8 commit 6808f67

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎assignments/closure.js‎

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

4+
// const name = "Barbara";
5+
6+
// function myName(){
7+
// console.log (`My name is ${name}`);
8+
// }
9+
10+
// myName();
11+
12+
413

514
// ==== Challenge 2: Create a counter function ====
615
const counter = () => {
16+
717
// Return a function that when invoked increments and returns a counter variable.
18+
counterVar = 0;
19+
return function numCounter(){
20+
counterVar++
21+
return counterVar;
22+
}
823
};
24+
25+
const f = counter()
26+
console.log(f())
27+
console.log(f())
28+
29+
30+
931
// Example usage: const newCounter = counter();
1032
// newCounter(); // 1
1133
// newCounter(); // 2

0 commit comments

Comments
 (0)