Skip to content

Commit 56dfbb4

Browse files
AlexAlex
authored andcommitted
made changes to closure.js
1 parent 6759a84 commit 56dfbb4

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎assignments/closure.js‎

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

4+
function whoAmI() {
5+
let identity = 'dog';
6+
function favoriteSnack() {
7+
let snack = 'smelly socks';
8+
console.log('Hi! I am a ' + identity + ' and I love to eat ' + snack + '.');
9+
}
10+
favoriteFood();
11+
}
12+
13+
whoAmI();
414

515
// ==== Challenge 2: Create a counter function ====
616
const counter = () => {
717
// Return a function that when invoked increments and returns a counter variable.
18+
let count = 0;
19+
return function () {
20+
count += 1;
21+
return count;
22+
}
823
};
24+
925
// Example usage: const newCounter = counter();
1026
// newCounter(); // 1
1127
// newCounter(); // 2

0 commit comments

Comments
 (0)