Skip to content

Commit aec3c60

Browse files
committed
Updates
1 parent 12af736 commit aec3c60

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

assignments/closure.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88

99
// Return a function that when invoked increments and returns a counter variable.
1010

11-
const counter = (count) => {
11+
const counter = () => {
12+
13+
let count = 0;
1214
function counterIncrement (){
13-
return count++;
15+
return ++count;
1416
}
1517
return counterIncrement;
1618
};
17-
const newCounter = counter(1);
19+
const newCounter = counter();
1820
console.log(newCounter());
1921
console.log(newCounter());
2022
console.log(newCounter());
@@ -46,7 +48,7 @@ const counterFactory = () => {
4648
return ++param;
4749
},
4850
decrement: function decrement () {
49-
return param--;
51+
return --param;
5052
}
5153
}
5254
};
@@ -56,7 +58,7 @@ const test = counterFactory();
5658
console.log(test.increment());
5759
console.log(test.increment());
5860
console.log(test.increment());
59-
console.log(`--------Decrement starts here---------------------------`);
61+
console.log(`-------- Decrement starts here ---------------------------`);
6062
console.log(test.decrement());
6163
console.log(test.decrement());
6264
console.log(test.decrement());

0 commit comments

Comments
 (0)