Skip to content

Commit 744ae8a

Browse files
committed
Attempt stretch goal challenge 3
-return an object which congtains 2 methods
1 parent 43536c5 commit 744ae8a

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎assignments/closure.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,23 @@ const counterFactory = () => {
4444
// Return an object that has two methods called `increment` and `decrement`.
4545
// `increment` should increment a counter variable in closure scope and return it.
4646
// `decrement` should decrement the counter variable and return it.
47+
let num = 0;
48+
const counter = {
49+
increment : function () {
50+
num++;
51+
return num;
52+
},
53+
decrement : function () {
54+
num--;
55+
return num;
56+
}
57+
}
58+
59+
return counter;
4760
};
61+
62+
const newFactory = counterFactory();
63+
console.log(newFactory.increment());
64+
console.log(newFactory.increment());
65+
console.log(newFactory.increment());
66+
console.log(newFactory.decrement());

0 commit comments

Comments
 (0)